WinConsole程序(PMPJ.EXE)不支持命令行参数输入,只支持标准输入。试图使用WinForm程序启动该程序后,将WinForm的输出重定向到PMPJ.EXE的标准输入。但执行到Process.Start()的时候,抛出异常:参数错误。
同样代码,启动CMDD.EXE成功,并在启动的窗口执行PING成功。
具体代码如下:
try
{
//ProcessStartInfo psi = new ProcessStartInfo("C:\\Users\\Jerry\\Documents\\Visual Studio 2008\\Projects\\TextDeal\\TextDeal\\cmdd.exe");
ProcessStartInfo psi = new ProcessStartInfo("C:\\Users\\Jerry\\Documents\\For DL\\2\\PMPJ.EXE");
psi.CreateNoWindow = true;
psi.RedirectStandardInput = true;
psi.RedirectStandardOutput = true;
psi.RedirectStandardError = true;
psi.Verb = "Open";
psi.UseShellExecute = false;
Process _process = new Process();
_process.OutputDataReceived += new DataReceivedEventHandler(_process_OutputDataReceived);
_process.StartInfo = psi;
_process.Start();
_process.BeginOutputReadLine();
this.button1.Enabled = false;
//_process.StandardInput.WriteLine("ping 192.168.1.1 -t\n");
_process.StandardInput.WriteLine(file.Name);
_process.StandardInput.WriteLine(file.Name.Replace(g_srcfileext, g_fileext));
_process.Close();
_process.Dispose();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}