开发者

How to run a Command in C# and retrieve data from it? [duplicate]

开发者 https://www.devze.com 2023-02-08 01:40 出处:网络
This question already has answers here: Closed 12 years ago. 开发者_StackOverflow Possible Duplicate:
This question already has answers here: Closed 12 years ago.
开发者_StackOverflow

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


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();
            }


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号