我试图让以下代码工作,所以我可以从我的c#程序调用perl脚本.我正在使用xd service pack3上的visual stdio 2008进行开发.
myProcess = new Process();
ProcessStartInfo myProcessStartInfo = new ProcessStartInfo("perl.exe");
myProcessStartInfo.Arguments = @"C:\Documents and Settings\test_perl.pl";
myProcessStartInfo.UseShellExecute = false;
myProcessStartInfo.RedirectStandardOutput = true;
myProcessStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
myProcessStartInfo.CreateNoWindow = true;
myProcess.StartInfo = myProcessStartInfo;
myProcess.Start();
string output = myProcess.StandardOutput.ReadToEnd();
MessageBox.Show(output);
myProcess.WaitForExit();
Run Code Online (Sandbox Code Playgroud)
我验证test_perl.pl存在,如果我将perl.exe更改为notepad.exe,则上述代码可以正常工作.但是,如果我使用perl.exe,则消息框为空.
无法弄清楚为什么这是错的.如果你知道原因,请帮助我.
谢谢