我想讓下面的代碼工作,所以我可以從我的 c#程序調用一個perl腳本。我正在開發在xp service pack3上使用visual stdio 2008。perl.exe不能被ProcessStartInfo調用
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,消息框是空的。
不知道爲什麼這是錯的。如果你知道原因,請幫助我。
謝謝
我不認爲文件路徑有任何問題,因爲如果我將perl.exe更改爲notepad.exe,它可以工作。 我也擺脫了myusername \ Documents \的目的。 – alex 2009-10-20 05:24:29
...無論如何嘗試。記事本!= perl。 – 2009-10-20 05:26:58
邁克爾,你很好!謝謝!它正在工作。但爲什麼額外的「」在那裏? – alex 2009-10-20 05:38:03