我有编译C ++程序生成的exe文件 现在我想通过C#将参数传递给生成的exe文件,并将exe文件的所有输出保存在.txt文件中 这就是我到目前为止所做的事情
public static string RunCmd(params int[] commands)
{
string returnvalue = string.Empty;
ProcessStartInfo info = new ProcessStartInfo("C:\\...\\.exe");
info.UseShellExecute = false;
info.RedirectStandardInput = true;
info.RedirectStandardOutput = true;
info.CreateNoWindow = true;
using (Process process = Process.Start(info))
{
StreamWriter sw = process.StandardInput;
StreamReader sr = process.StandardOutput;
//foreach (int command in commands)
//{
// sw.WriteLine(command);
//}
for (int i = 0; i < commands.Length; i++)
{
sw.WriteLine(commands[i]);
}
sw.Close();
returnvalue = sr.ReadToEnd();
process.Close();
System.IO.StreamWriter file = new System.IO.StreamWriter("C:\\..\\.txt");
file.WriteLine(returnvalue);
file.Close();
return returnvalue;
}
它适用于单个参数 但每当我尝试输入多个参数时,它只会打开.exe文件而不能进一步工作