我希望能够将参数传递给另一个由C#开发的exe文件。 我知道如何从我的应用程序向exe文件传递参数。这样我就可以传递参数到exe文件。
Process p= new Process();
p.StartInfo.FileName = "demo.exe";
p.StartInfo.Arguments = "param1 param2";
p.Start();
p.WaitForExit();
现在demo.exe文件将会执行某些任务并返回一些数据。我想在我的端口捕获这些数据。请指导我如何更改我的代码以捕获demo.exe文件返回的响应。请提供修改后的代码。谢谢。
可能下面的解决方案可以解决我的问题。我会测试它。 当您创建Process对象时,请适当设置StartInfo:
var proc = new Process {
StartInfo = new ProcessStartInfo {
FileName = "program.exe",
Arguments = "command line arguments to your executable",
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
}
};
then start the process and read from it:
proc.Start();
while (!proc.StandardOutput.EndOfStream) {
string line = proc.StandardOutput.ReadLine();
// do something with line
}
Process.ExitCode
: https://msdn.microsoft.com/zh-cn/library/system.diagnostics.process.exitcode(v=vs.110).aspx - Matjaž