Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DOS commando put to textfile 2

Status
Not open for further replies.

dukkse

Technical User
Oct 15, 2003
42
US
Hey!!

I have a script (bat-file) to gather info about servers information, and I want to convert it to vbs.

everything works fine and it does what it should if I write like this:

shell.run "srvinfo -s \\" & Server

But, If I want to save the outcoming info it stops working. This is the line I write then:

shell.run "srvinfo -s \\" & Server & " > \\" & sLogServer & "\" & Server & ".txt", 0, True

Is there anything that vbscript doesn't like in this??

Please help

/Daniel
 
Try this:
Code:
shell.run "%COMSPEC% /C srvinfo -s \\" & Server  & " > \\" & sLogServer & "\" & Server & ".txt", 0, True


Hope This Help
PH.
 
Thanks but sorry, it didn´t help.

I think it has something with the piping. Because even if you type in

shell.run "ipconfig > test.txt"

for example, it will not pipe out the text to that file.

/D
 
And this ?
Code:
shell.run "cmd /c ipconfig > test.txt"


Hope This Help
PH.
 
dukkse,

Try this.

svr = "yourservername"
outfile = "Path\filename"

Set WshShell = Wscript.CreateObject("Wscript.Shell")
WshShell.run ("cmd /C ""srvinfo \\" & svr & " > " & outfile & " "" ")
 
Well, it's getting there. FengShui, your tip created the file, but still no data in it.. But at least the file is now created..

Any more ideas????
 
Yet another method :
Code:
Set oSh=CreateObject("WScript.Shell")
Set oEx=oSh.Exec("srvinfo -s \\" & Server)
Do While oEx.Status=0
  WScript.Sleep 100
Loop
buf=oEx.StdOut.ReadAll
Set fso=CreateObject("Scripting.FileSystemObject")
Set MyFile=fso.CreateTextFile("\\" & sLogServer & "\" & Server & ".txt",True)
MyFile.WriteLine buf
MyFile.Close

Hope This Help
PH.
 
Thanks, it works fine on my XP box, but then when I load it to the Win2000 Server, it just creates the files, but they are empty.. But works really nice on XP, any idea???
 
dukkse,

This is how I handle command-line exe's in VBS:

Set WshShell = Wscript.CreateObject("Wscript.Shell")
svr = "yourservername"
outfile = "Path\filename"

DoThisCommand = "cmd /c srvinfo \\ & svr & " > " & outfile

NowRunIt = WshShell.Run(DoThisCommand,,true)


This can be helpful when constructing the command-line sequence (at least its more logical ME, your mileage may vary) PLUS, you can test the variable 'NowRunIt' and USUALLY anything > 0 means something bad happened.

Hope this helps.
 
sorry, left out a ". Should read as follows:

DoThisCommand = "cmd /c srvinfo \\" & svr & " > " & outfile
 
On the Win2000, you can try to read this stream too:
Code:
buf=oEx.StdErr.ReadAll

Hope This Help
PH.
 
Hey Jeffatemc!!

Nice work, it works fine now.. Thanks guys for all your help.. It wasn't that hard, just that my experience isn't the best..

Let me know if theres more ideas..

/Daniel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top