2

Possible Duplicate:
How To: Execute command line in C#, get STD OUT results

Hello,

In my C# application, I want to run a Command from command promt and want its output and maipulate its output. If required, want to close the process and display error or appropriate message. To stop the process, I have to press "F4' key on command prompt. Till the process is stopeed or killed, it has to be alive only.

How is that possible. Any help is highly appreciated. I am stuck with this and would be glad if any body helps me solve my problem.

Thanks

Community
  • 1
  • 1
Tvd
  • 4,463
  • 18
  • 79
  • 125

3 Answers3

2

Do you need something like this

ProcessStartInfo startInfo = new ProcessStartInfo
            {
                CreateNoWindow = false,
                UseShellExecute = false,
                FileName = @"program",
                WindowStyle = ProcessWindowStyle.Normal,
                Arguments = "agruments"
            };

            using (Process exeProcess = Process.Start(startInfo))
            {
                if (exeProcess != null) exeProcess.WaitForExit();
            }
Kimtho6
  • 6,154
  • 9
  • 40
  • 56
0

Try this:

http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardoutput.aspx

But I don't think we can stop execution of the command by putting F4 on command line.

Anuraj
  • 18,859
  • 7
  • 53
  • 79
  • Thanks, I got the part of creating object of Process. I am basically trynig to connect to a server and the server gives output till it is not disconnected. – Tvd Feb 03 '11 at 08:57
0

You may try using Process under System.Diagnostics to launch and get the outputs Can you please elaborate on what type of commands and the intent of it, not clear on that part

V4Vendetta
  • 37,194
  • 9
  • 78
  • 82
  • As this thread is marked as "CLOSED" I don't think I will be able to shaer more with you on this thread. But I need more than this. Kindly refer to http://stackoverflow.com/questions/4884175/manipulate-the-output-receiving-from-command-run-and-act-accordingly-c to know more avout my problem. its not just like execute a "dir" ike command, retrieve output and the process is already "Exited". It way more than that. I need your guidance, please help me to your best. - Thanks – Tvd Feb 03 '11 at 09:17