
Redirect output to text file |
Post Reply
|
| Author | |
praseetha
I'm new here
Joined: 15 May 2007 Online Status: Offline Posts: 16 |
Quote Reply
Topic: Redirect output to text filePosted: 10 Jul 2007 at 02:30 |
|
Hi,
Given below is the code that i use to send the output of ipconfig to a text file.
strRun = "ipconfig >C:\Documents and Settings\inpka\Desktop\Test\New Text Document.txt"
objShell.Run strRun, 1, True which does not output to text file. But When i run the same command in command prompt i give as
ipconfig >"C:\Documents and Settings\inpka\Desktop\Test\New Text Document.txt" i can view the output in the text file howeverin cmd prompt, It works only when i give the path within quotes
Could someone pld guide onthis..
regards,
Praseetha
Edited by praseetha - 10 Jul 2007 at 02:59 |
|
![]() |
|
dm_4ever
Regular Member
Joined: 06 Jul 2007 Online Status: Offline Posts: 68 |
Quote Reply
Posted: 10 Jul 2007 at 06:40 |
|
When you run it from the command prompt you add the extra quotes...so you need to do the same in your code.
|
|
![]() |
|
praseetha
I'm new here
Joined: 15 May 2007 Online Status: Offline Posts: 16 |
Quote Reply
Posted: 11 Jul 2007 at 07:27 |
|
Hi,
Given below is the code I used:
Dim objShell,objFile,objFso,strTmp,strCommand,strInput
Set objShell = WScript.CreateObject("WScript.Shell") Set objFso = CreateObject("Scripting.FileSystemObject") strTmp = "C:\Documents and Settings\inpka\Desktop\Test\textfile.txt" strCommand = "ipconfig > " & Quote(strTmp) objShell.Run strCommand,7,True Function Quote(s)
Quote = Chr(34) & CStr(s) & Chr(34) End Function This did not forward output to text file.
This is smething very critical for us. Is there a way I can make this happen.
Thanks,
Praseetha
|
|
![]() |
|
AbqBill
Frequent Contributor
Joined: 31 Aug 2006 Online Status: Offline Posts: 246 |
Quote Reply
Posted: 11 Jul 2007 at 09:30 |
|
Hi Praseetha,
Output redirection is a feature of the command shell. The fix is to call cmd.exe to execute your command. Here's an example in JScript that's pretty easily adapted to VBScript:
HTH, Bill |
|
![]() |
|
joseomjr
Regular Member
Joined: 31 Aug 2006 Online Status: Offline Posts: 68 |
Quote Reply
Posted: 11 Jul 2007 at 10:34 |
|
This should be the same as what Bill showed you in VBScript
strRun = "%comspec% /c ipconfig.exe > " & AddQuotes("C:\Documents and Settings\inpka\Desktop\Test\New Text Document.txt") |
|
![]() |
|
AbqBill
Frequent Contributor
Joined: 31 Aug 2006 Online Status: Offline Posts: 246 |
Quote Reply
Posted: 11 Jul 2007 at 15:00 |
|
Hi joseomjr,
Don't forget to call the ExpandEnvironmentStrings method to expand the %ComSpec% environment variable. HTH, Bill |
|
![]() |
|
dm_4ever
Regular Member
Joined: 06 Jul 2007 Online Status: Offline Posts: 68 |
Quote Reply
Posted: 11 Jul 2007 at 16:24 |
|
You don't need to in this case. .Run will know what to do with it.
|
|
![]() |
|
AbqBill
Frequent Contributor
Joined: 31 Aug 2006 Online Status: Offline Posts: 246 |
Quote Reply
Posted: 12 Jul 2007 at 09:11 |
|
Hi dm_4ever,
Good tip. It's even documented in the docs for the Run method. Thanks. Bill |
|
![]() |
|
praseetha
I'm new here
Joined: 15 May 2007 Online Status: Offline Posts: 16 |
Quote Reply
Posted: 13 Jul 2007 at 03:34 |
|
Hi All,
strRun = "%comspec% /c ipconfig > " & AddQuotes("C:\Documents and Settings\inpka\Desktop\Test\New Text Document.txt")This outputs teh result to a text file. Now, I have written a script which will go and check some files. Based on the file name the script gets(based on condition set), I need to run a command say "Eseutil /mk xyz.chk" in I:\logs directory in command prompt. Can someone pls suggest as to how i can put the above command in "%comspec% /c ipconfig > " ( instead of ipconfig, i need to execute this command. The problem is that the command line should execute this comand frmo I:\logs. How can i have this done? Thanks, Praseetha |
|
![]() |
|
AbqBill
Frequent Contributor
Joined: 31 Aug 2006 Online Status: Offline Posts: 246 |
Quote Reply
Posted: 16 Jul 2007 at 08:34 |
|
Hi Praseetha,
I believe you can use the CurrentDirectory property of the WshShell object to set the current working directory for a script. For example:
HTH, Bill |
|
![]() |
|
praseetha
I'm new here
Joined: 15 May 2007 Online Status: Offline Posts: 16 |
Quote Reply
Posted: 18 Jul 2007 at 00:20 |
|
Hi All..
Thanks a lot for your assistance:)
Regards,
Praseetha
|
|
![]() |
|
Post Reply
|
| Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |