Capture stdout while waiting for command to finish

Batch, ASP, JScript, Kixtart, etc.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
tuanto@eview-tech.com
Posts: 3
Joined: Tue Oct 26, 2010 6:09 am

Capture stdout while waiting for command to finish

Post by tuanto@eview-tech.com » Thu Apr 28, 2011 4:05 am

Hello VBscript expert,I am running a Dos command in my vbscript and try to capture all output when the command completes and write to a file. Some times I can capture 1 or 2 lines and miss the rest. Here is a section of my code...Set oFile1 = oFso1.OpenTextFile(LogFile, ForWriting)CommandLine = oArgs(0) & "binEV400hostcmd 86 28." & SNodeSet objWShell = CreateObject("WScript.Shell")Set objWExec = objWShell.Exec(CommandLine)'Capture the output of the command line Do Until objWExec.StdOut.AtEndOfStream strLine = objWExec.StdOut.ReadLine oFile1.WriteLine(strLine) 'WScript.Echo strLine Loop....Can you help?Thanks,Tto

User avatar
tuanto@eview-tech.com
Posts: 3
Joined: Tue Oct 26, 2010 6:09 am

Capture stdout while waiting for command to finish

Post by tuanto@eview-tech.com » Thu Apr 28, 2011 4:05 am

Hello VBscript expert,I am running a Dos command in my vbscript and try to capture all output when the command completes and write to a file. Some times I can capture 1 or 2 lines and miss the rest. Here is a section of my code...Set oFile1 = oFso1.OpenTextFile(LogFile, ForWriting)CommandLine = oArgs(0) & "binEV400hostcmd 86 28." & SNodeSet objWShell = CreateObject("WScript.Shell")Set objWExec = objWShell.Exec(CommandLine)'Capture the output of the command line Do Until objWExec.StdOut.AtEndOfStream strLine = objWExec.StdOut.ReadLine oFile1.WriteLine(strLine) 'WScript.Echo strLine Loop....Can you help?Thanks,Tto

jvierra
Posts: 13882
Joined: Tue May 22, 2007 9:57 am
Contact:

Capture stdout while waiting for command to finish

Post by jvierra » Thu Apr 28, 2011 4:12 am

Please do not post VBSxeipt questions to the command line forum. It is likely that no one will see you request.

You need to wait until the command completes before you try to red the results.

Do While objWExec .Status <> 1 WScript.Sleep 100Loop

See: http://msdn.microsoft.com/en-us/library ... S.85).aspx
jvierra2011-04-28 11:19:52

Locked