我正在尝试使以下代码正常工作,以便可以从我的 c# 程序中调用 perl 脚本。我正在 xp 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();
我验证了 test_perl.pl 是否存在,如果我将 perl.exe 更改为 notepad.exe,则上面的代码可以工作。但是如果我使用 perl.exe,消息框是空的。
无法弄清楚为什么这是错误的。如果您知道原因,请帮助我。
谢谢