C# WinForm程序,创建一WinConsole程序不成功,提示“参数错误”

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());
}

第1个回答  2010-12-13
string SubDirectoryName="要删除的目录名"
Process process = new Process();
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.Arguments = " /C rmdir " + SubDirectoryName + " /s /q";
process.Start();

希望对你有帮助。以前我调用这类去运行DOS命令用到的
第2个回答  2010-12-13
现在还在做平台设计吗??为什么不做.NET的呢本回答被网友采纳
第3个回答  2010-12-25
什么来的
相似回答