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.
This topic is 12 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
tuanto@eview-tech.com
Posts: 3
Last visit: Thu Apr 28, 2011 4:05 am

Capture stdout while waiting for command to finish

Post by tuanto@eview-tech.com »

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
Last visit: Thu Apr 28, 2011 4:05 am

Capture stdout while waiting for command to finish

Post by tuanto@eview-tech.com »

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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Capture stdout while waiting for command to finish

Post by jvierra »

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
This topic is 12 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked