Process相关问题
要在C#程序中调用一个名为mencoder的命令行程序,mencoder需要在DOS环境下运行,于是我就用Process对象调用了cmd.exe 如下:
Process p = new Process();
p.StartInfo.FileName = "cmd.exe ";
然后我通过cmd.exe来执行mencoder,如下:
p.StandardInput.WriteLine(@ "mencoder 参数N.... ");
p.StandardInput.WriteLine( "exit ");
但我想知道mencoder程序是否执行成功,怎么在程序中获取?
好象有个p.ExitCode,但我不是很清楚...
------解决方案--------------------我是这样测试的
Process vProcess = new Process();
vProcess.StartInfo.FileName = "cmd.exe ";
vProcess.StartInfo.UseShellExecute = false;
vProcess.StartInfo.RedirectStandardInput = true;
vProcess.StartInfo.RedirectStandardOutput = true;
vProcess.StartInfo.RedirectStandardError = true;
vProcess.StartInfo.CreateNoWindow = false;
vProcess.Start();
vProcess.StandardInput.WriteLine(@ "xxxxx.exe ");
vProcess.StandardInput.WriteLine( "exit ");
textBox1.Text = vProcess.StandardOutput.ReadToEnd();
Console.WriteLine(vProcess.ExitCode);
vProcess.Close();