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 3 3228
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#)
------------------------------------------------------------------------
> 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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Jeff Jarrell |
last post by:
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...
|
by: Michael Smith |
last post by:
Hi,
I am using the following code to print documents directly
to the default printer
**************
ProcessStartInfo startInfo = new ProcessStartInfo
("<someprogram>.exe");...
|
by: Fei Yuan |
last post by:
Please forgive me re-posting this question since I wasn't clear in my
original post.
-------->
Starting an external process needs to pass it a ProcessStartInfo() object.
ProcessStartInfo has a...
|
by: jam |
last post by:
Dear All,
I have a command process running xcopy in console, and now I want to execute
the program Rsync After the files are copied...how could i do??
Process p10=new Process();...
|
by: CroDude |
last post by:
Hi all!
Please help me with this, I'm stuck here.
I have a command line .exe file which needs a few arguments passed to do
it's job.
In help there's a example like this:
...
|
by: Samantha |
last post by:
Hello ,
I am developping a program for Win98 plateform, and I am stucking with a
problem, hope you can help me.
I have a program running 2 process :
- One process running the Xcopy.exe
-...
|
by: Trond |
last post by:
I am trying to start a console program from an event in a ASP.NET page. In
the folder where the EXE is there is a config file. Here is some code i
wrote that should start the exe file:
...
|
by: Scott B |
last post by:
I have a EXE that spits out text in XML fomat.
I need to call this exe and have it write the XML to a file
I am using the following code:
System.Diagnostics.Process p = new...
|
by: Phonon |
last post by:
Hi All,
I'm a little new to .NET and I'm having a threading issue I'm
having a problem resolving/understanding.
I'm making a plug-in into Word. A menu-option ('Check Updates')
spawns a new...
|
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= |
last post by:
Hello,
I have a C# application in which I start another process which produces
output to stdout and stderr. In fact, that process is the uSoft VS2005 C/C++
compiler itself! I would like to...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| | |