首页 > 技术文章 > c# 运行进程,并获取进程执行结果

zhangj391 2017-04-11 13:10 原文

static void Main(string[] args)
{
Process process = new Process();
process.StartInfo.FileName = AppDomain.CurrentDomain.BaseDirectory + "myTest.exe";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardInput = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.CreateNoWindow = true;

process.OutputDataReceived += (sender, e) =>
{
string data = e.Data;
if (data == "ok")
{
Console.WriteLine("启动成功!");
}
};

process.Start();
process.BeginOutputReadLine();

Console.Read();
}

推荐阅读