By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,571 Members | 994 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,571 IT Pros & Developers. It's quick & easy.

Process.startinfo, I am stuck

P: n/a
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
Nov 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Jeff Jarrell wrote:
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.
In your code, is sExecutable the FULL path + exe name or just the exe
name? Please specify the full path. Also, set the working directory to
the folder where your .exe is located. Did that make it work?

Btw, it can be stdout/err aren't capturable when you run an exe, for
example if it's not a console app.

FB

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


--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Nov 22 '05 #2

P: n/a
> If it is a *.bat file it works. If it is a *.exe it doesn't.

My formula for an exe is shown below. I stopped experimenting when I got it
to work, so I don't know precisely what is necessary and what is not.

Dim s as String
Dim p As New Process
With p.StartInfo
.FileName = "..." ' exe path goes here
.Arguments = "..." ' args go here
.UseShellExecute = False
.RedirectStandardError = True
.RedirectStandardInput = True
.RedirectStandardOutput = True
.WindowStyle = ProcessWindowStyle.Hidden
.CreateNoWindow = True
End With
Try
p.Start()
s = p.StandardOutput.ReadToEnd()
p.WaitForExit()
Catch e As Exception
s = e.tostring
End Try

Nov 22 '05 #3

P: n/a
I put your stuff in and it worked. I hope to get a chance to dig into why
it wasn't work for me before...

thanks.

"AMercer" <AM*****@discussions.microsoft.com> wrote in message
news:BC**********************************@microsof t.com...
If it is a *.bat file it works. If it is a *.exe it doesn't.


My formula for an exe is shown below. I stopped experimenting when I got
it
to work, so I don't know precisely what is necessary and what is not.

Dim s as String
Dim p As New Process
With p.StartInfo
.FileName = "..." ' exe path goes here
.Arguments = "..." ' args go here
.UseShellExecute = False
.RedirectStandardError = True
.RedirectStandardInput = True
.RedirectStandardOutput = True
.WindowStyle = ProcessWindowStyle.Hidden
.CreateNoWindow = True
End With
Try
p.Start()
s = p.StandardOutput.ReadToEnd()
p.WaitForExit()
Catch e As Exception
s = e.tostring
End Try

Nov 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.