Calling an executable that runs on the command line and fetching return values
I've done a lot of API stuff in my time, real hardcore but am a bit out of touch now.
From within my VB.NET WinForms app, I want to call an external executable. The said executable runs on a command line and takes two params.
Calling the executable is no biggie. I could use the old VB 6 shell, or the Win32 API ShellExecuteEx or CreateProcess to fork a new process. The problem is getting the status of the process and its return values of success of failure.
Can you please help?
Re: Calling an executable that runs on the command line and fetching return values
If you are going to use .NET, then there is no reason to use Shell. Try this
vb.net Code:
Dim att As String = "yourexeprogram.exe"
Dim params As String = "/param1 /param2"
Dim p As New Process
p = System.Diagnostics.Process.Start(att, params)
Re: Calling an executable that runs on the command line and fetching return values
Thank you, but the problem, as stated, is not starting the external process. It is fetching the status and return values from it.
Do you know how that can be done?
Re: Calling an executable that runs on the command line and fetching return values
Re: Calling an executable that runs on the command line and fetching return values
Thanks, Doogle, but I also want the string values returned. GetExitCodeProcess only returns integers/longs.
Any idea?
Re: Calling an executable that runs on the command line and fetching return values
So, does this command line process actually write the 'results' to the standard output? (stdOut)
If so, you can re-direct the standard output of the created process to a pipe which is connected to your process at the time you call CreateProcess. Then anything written to the standard output of the command line process will appear at your end of the pipe.
If you use an asynchronous pipe it will effectively raise an event in your code when it writes to the standard output, meaning that the two process can run asynchronously, but one can be 'informed' when the other terminates, together with the termination information.
If you efficetively want to wait for the command line process to finish, then using a synchronous pipe would do. (you'd issue a synchronous 'Read' on the Pipe and wait for something to be returned)
Not particularly easy to implement but doable.