如何在C#中运行一个命令并从中检索数据? [英] How to run a Command in C# and retrieve data from it?
本文介绍了如何在C#中运行一个命令并从中检索数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
在我的C#应用程序中,我想从命令promt运行一个命令,并计算其输出。如果需要,要关闭过程并显示错误或适当的消息。要停止进程,我必须在命令提示符下按F4键,直到进程停止或杀死,它只能活着。
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.
。
感谢
推荐答案
您需要这样的
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();
}
这篇关于如何在C#中运行一个命令并从中检索数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文