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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

objShell.Run "cmd to text variable?

Status
Not open for further replies.

Calz

Technical User
Nov 14, 2001
103
FR
Hi,

I'm trying to redirect a cmd based script to a txt file, as it stand it goes...

objShell.Run "cmd /c S:\update1.cmd >>c:\file.txt",1,True
objShell.Run "cmd /c S:\update2.cmd >>c:\file.txt",1,True

This all works ok and sends the output from within the commands to the file but I want to specify the file as a variable so...

objShell.Run "cmd /c s:\update1.cmd >>strFileName",1,True
objShell.Run "cmd /c s:\update2.cmd >>strFileName",1,True

Obviously this doesn't work as it's within "" and using & doesn't work.

How do I get round this?
BTW I can't modify update1.cmd and strFileName with have spaces in the path.
 
>objShell.Run "cmd /c s:\update1.cmd >>strFileName",1,True
[tt]objShell.Run "cmd /c s:\update1.cmd >>[red]" & strFileName[/red],1,True[/tt]
 
Why not assign the the command a variable? Something like...

strCommand = objShell.Run ("cmd /c S:\update1.cmd",1,True)
Set objExecObject = objShell.Exec(strCommand)
Set objStdOut = objWshScriptExec.StdOut

Do Until objStdOut.AtEndOfStream
strLine = objStdOut.ReadLine
Wscript.Echo strLine
Loop


This will allow you to read thru the output information. There is other code out there to allow you to then output to text file, excel, etc. Not sure if all of this code it correct but maybe it can get you on the right path.

Good Luck!!
 
Doesn't send text to file Tsuji I tried that before, I don't need to anything fancy with the output just be able to log it to a text file nothing else :)
 
How does strFileName look like! If there is no space inside, why shouldn't it send?
 
strFileName has spaces as mentioned in my first post.

I use strFileName elsewhere and all is good.
 
[tt]objShell.Run "cmd /c s:\update1.cmd >>" &[red] chr(34) & strFileName & chr(34)[/red],1,True[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top