running an executable program from 2005


I have a program and I would like it to run an executable. It's a perl program and it sends any error message to standard error which seems to mean when i run it at a command prompt it prints the messages at the console window.

How would i run this program from within and and catch its error messages.

Many thanks
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Redirecting process outputs and so forth... pretty interesting actually. might have a blast on one of my own projects...

Code is here in case there was a problem with the link...

Dim myProcess As Process = New Process()
   Dim s As String
   myProcess.StartInfo.FileName = "cmd.exe"
   myProcess.StartInfo.UseShellExecute = False
   myProcess.StartInfo.CreateNoWindow = True
   myProcess.StartInfo.RedirectStandardInput = True
   myProcess.StartInfo.RedirectStandardOutput = True
   myProcess.StartInfo.RedirectStandardError = True
   Dim sIn As System.IO.StreamWriter = myProcess.StandardInput
   sIn.AutoFlush = True
   Dim sOut As System.IO.StreamReader = myProcess.StandardOutput
   Dim sErr As System.IO.StreamReader = myProcess.StandardError
   sIn.Write("program_to_be_executed" & "programs_arguments" & System.Environment.NewLine)
   sIn.Write("exit" & System.Environment.NewLine)
   s = sOut.ReadToEnd()
   If Not myProcess.HasExited Then
   End If


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
I havent checked the link above but herez the code that I use in one of my programs :

            Dim pWinRar As Process = System.Diagnostics.Process.Start(m_WinRARpath, strParam)
            intExitCode = pWinRar.ExitCode
Announcing the Winners!

The results are in for the 15th Annual Expert Awards! Congratulations to the winners, and thank you to everyone who participated in the nominations. We are so grateful for the valuable contributions experts make on a daily basis. Click to read more about this year’s recipients!

andiejeAuthor Commented:

That's great - thanks very much.

A couple of questions:

1. How do i access any error message produced from the program. I can see that you create an input stream on the standard error but its never used. Would you just call the readtoend method on the error stream like you do with the input stream.

2. Is there any way to access the errors in the error stream as they happen. I'm not sure if i need to do this as it's not like i can interact with the program when it reports an error message but it feels like it might be a useful thing to know

thanks a lot
Theres two output streams taken in the code i've posted. If the errors aren't part of the standard error stream then i would assume they would be sent down the standard output pipe.

I've not really played with this code, but im sure you could execute a loop on a seperate thread to constantly read to the end of each stream and raise and event when new data (possibly your error) is 'received'?

andiejeAuthor Commented:
Thank-you very much
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.