DOS Command with Error Handling

I am looking for a routine to do the following:

  1) Open a DOS prompt (on a Win 2003 server)
  2) Send DOS commands to a program (an FTP program)
  3) Wait for the handle or an error to return
  4) Be able to recognize when the handle has been gone too long (probably using a timer here, unless there's a way to set a time limit).

This might be a tall order, so reference links would be fine if they show me how to accomplish this. The primary part of this request is to recognize the handle's return and catch and DOS errors.

Thanks in advance!

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.

JeepGeekinAuthor Commented:
OK #4 is a luxury item. Anyone know how to accomplish 1-3?
You will not be able to control FTP.exe that way.

Write your own FTP client instead:;EN-US;832679
JeepGeekinAuthor Commented:
Great post! I'll accept it if no one has a better solution. My problem is that I also have to decrypt the file using a program that takes DOS commands.

Do we completely loose control of the handle sending DOS commands from I was hoping that there was a way to retain control.
DOS commands are not written like APIs that your program can use.  Input and Output is assumed from and to the console.  You have limited control of these commands from your VB.NET application.

You can, however, redirect the standard Input and Output of these commands to your program:

        ' Create a DOS command and redirect its output so we can capture it
        Dim pi As ProcessStartInfo = New ProcessStartInfo("cmd.exe")
        pi.RedirectStandardInput = True
        pi.RedirectStandardOutput = True
        pi.UseShellExecute = False

        ' Run the DOS command
        Dim proc As Process = Process.Start(pi)
        proc.StandardInput.WriteLine("dir c:")

        ' Capture DOS command output
        Dim output As String = proc.StandardOutput.ReadToEnd()

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
JeepGeekinAuthor Commented:
Thanks Dimandja. I haven't had a chance to test this, but it's exactly what I am looking for. Thanks a bunch!
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.