J
Jeff Jarrell
I have an object to execute a process. its intent is to do a simple execute
and capture stdin and stdout. Nothing fancy, not for long processes. simple.
I expect to typically use it with a fully qualified path for the executable.
If it is a *.bat file it works. If it is a *.exe it doesn't. When it
doesn't work (calling an exe file) I get an "Unrecognized Command" with an
exit code of 100. If I call a bat file it works. I have tried the
shellexecute = false, but i get a message that you can't capture stdin,
stdout. I have also tried using the workingDirectory as well to no avail.
thanks,
jeff
Public Function Execute(ByVal sExecutable As String, ByVal sParms As String,
ByVal bShowWindow As Boolean) As Integer
Reset()
Dim myProcess As Process
myProcess = New Process
myProcess.StartInfo.UseShellExecute = False
myProcess.StartInfo.FileName = sExecutable
myProcess.StartInfo.WorkingDirectory = ""
myProcess.StartInfo.Arguments = sParms
myProcess.StartInfo.CreateNoWindow = Not bShowWindow
myProcess.StartInfo.RedirectStandardOutput = True
myProcess.StartInfo.RedirectStandardError = True
myProcess.Start()
Dim sOut As StreamReader = myProcess.StandardOutput
Dim sErr As StreamReader = myProcess.StandardError
Me._stdOut = sOut.ReadToEnd()
Me._stdErr = sErr.ReadToEnd
If Not myProcess.HasExited Then
myProcess.Kill()
End If
sOut.Close()
sErr.Close()
_exitCode = myProcess.ExitCode
myProcess.Dispose()
Return _exitCode
End Function
and capture stdin and stdout. Nothing fancy, not for long processes. simple.
I expect to typically use it with a fully qualified path for the executable.
If it is a *.bat file it works. If it is a *.exe it doesn't. When it
doesn't work (calling an exe file) I get an "Unrecognized Command" with an
exit code of 100. If I call a bat file it works. I have tried the
shellexecute = false, but i get a message that you can't capture stdin,
stdout. I have also tried using the workingDirectory as well to no avail.
thanks,
jeff
Public Function Execute(ByVal sExecutable As String, ByVal sParms As String,
ByVal bShowWindow As Boolean) As Integer
Reset()
Dim myProcess As Process
myProcess = New Process
myProcess.StartInfo.UseShellExecute = False
myProcess.StartInfo.FileName = sExecutable
myProcess.StartInfo.WorkingDirectory = ""
myProcess.StartInfo.Arguments = sParms
myProcess.StartInfo.CreateNoWindow = Not bShowWindow
myProcess.StartInfo.RedirectStandardOutput = True
myProcess.StartInfo.RedirectStandardError = True
myProcess.Start()
Dim sOut As StreamReader = myProcess.StandardOutput
Dim sErr As StreamReader = myProcess.StandardError
Me._stdOut = sOut.ReadToEnd()
Me._stdErr = sErr.ReadToEnd
If Not myProcess.HasExited Then
myProcess.Kill()
End If
sOut.Close()
sErr.Close()
_exitCode = myProcess.ExitCode
myProcess.Dispose()
Return _exitCode
End Function