G
Guest
Hello,
I am attempting to start a cmd.exe process and pass several .vbs scripts
(with additional parameters) and then read the output from the scripts and
make "notes" in a DataTable (the "notes" not being the issue).
Beginning with...
Dim objProcess As Process
Dim objProcessStartInfo As New ProcessStartInfo
objProcessStartInfo.FileName =
System.Environment.GetEnvironmentVariable("ComSpec")
objProcessStartInfo.WorkingDirectory =
System.Environment.GetEnvironmentVariable("SystemRoot")
objProcessStartInfo.RedirectStandardOutput = True
objProcessStartInfo.RedirectStandardInput = True
objProcessStartInfo.RedirectStandardError = True
objProcessStartInfo.UseShellExecute = False
objProcessStartInfo.WindowStyle = ProcessWindowStyle.Normal
objProcess = Process.Start(objProcessStartInfo)
I then loop through a DataTable, attempting to fire off VBScripts (or
Batch/EXE)(a.k.a. strApplicationAction) using:
objProcess.StandardInput.WriteLine(strApplicationAction)
Ex. strApplicationAction = "C:\Scratch\CopyFile.vbs MyComputer"
then attempt to read the output from the VBScript using
objProcess.StandardOutput. I have tried all of the following:
' Problem: EndOfStream is not reached when VBScript ends only when cmd.exe
closes.
Do While (objProcess.StandardOutput.EndOfStream = False)
strOutput &= objProcess.StandardOutput.ReadLine & vbCrLf
Loop
' Problem: Hangs because it is looking for the exit of the cmd.exe
strOutput = objProcess.StandardOutput.ReadToEnd
' If condition not reached until cmd.exe is closed
Do While (objProcess.StandardOutput.EndOfStream = False)
strTemp &= objProcess.StandardOutput.ReadLine
if (strTemp = System.Environment.GetEnvironmentVariable("SystemRoot") &
">") then exit do
Loop
Note: I can collect the StandardOutput. I am just getting tripped up on
knowing when the cmd.exe is idle. What I am looking for is the ability to
determine if the cmd.exe is finished processing the first VBScript/Batch/EXE
and then fire another one using
objProcess.StandardInput.WriteLine(strApplicationAction) without having to
launch a new cmd.exe for each ApplicationAction (I already have that working
~ 100 scripts = 100 cmd.exe (or cscript.exe)). Is it even possible to read
the status of cmd.exe? Do I need to use StandardError somehow? I have
already tried WaitForInputIdle (GUI only).
Thanks in advance.
I am attempting to start a cmd.exe process and pass several .vbs scripts
(with additional parameters) and then read the output from the scripts and
make "notes" in a DataTable (the "notes" not being the issue).
Beginning with...
Dim objProcess As Process
Dim objProcessStartInfo As New ProcessStartInfo
objProcessStartInfo.FileName =
System.Environment.GetEnvironmentVariable("ComSpec")
objProcessStartInfo.WorkingDirectory =
System.Environment.GetEnvironmentVariable("SystemRoot")
objProcessStartInfo.RedirectStandardOutput = True
objProcessStartInfo.RedirectStandardInput = True
objProcessStartInfo.RedirectStandardError = True
objProcessStartInfo.UseShellExecute = False
objProcessStartInfo.WindowStyle = ProcessWindowStyle.Normal
objProcess = Process.Start(objProcessStartInfo)
I then loop through a DataTable, attempting to fire off VBScripts (or
Batch/EXE)(a.k.a. strApplicationAction) using:
objProcess.StandardInput.WriteLine(strApplicationAction)
Ex. strApplicationAction = "C:\Scratch\CopyFile.vbs MyComputer"
then attempt to read the output from the VBScript using
objProcess.StandardOutput. I have tried all of the following:
' Problem: EndOfStream is not reached when VBScript ends only when cmd.exe
closes.
Do While (objProcess.StandardOutput.EndOfStream = False)
strOutput &= objProcess.StandardOutput.ReadLine & vbCrLf
Loop
' Problem: Hangs because it is looking for the exit of the cmd.exe
strOutput = objProcess.StandardOutput.ReadToEnd
' If condition not reached until cmd.exe is closed
Do While (objProcess.StandardOutput.EndOfStream = False)
strTemp &= objProcess.StandardOutput.ReadLine
if (strTemp = System.Environment.GetEnvironmentVariable("SystemRoot") &
">") then exit do
Loop
Note: I can collect the StandardOutput. I am just getting tripped up on
knowing when the cmd.exe is idle. What I am looking for is the ability to
determine if the cmd.exe is finished processing the first VBScript/Batch/EXE
and then fire another one using
objProcess.StandardInput.WriteLine(strApplicationAction) without having to
launch a new cmd.exe for each ApplicationAction (I already have that working
~ 100 scripts = 100 cmd.exe (or cscript.exe)). Is it even possible to read
the status of cmd.exe? Do I need to use StandardError somehow? I have
already tried WaitForInputIdle (GUI only).
Thanks in advance.