2015-06-02 145 views
0

我使用這個代碼運行從C#程序中的Perl腳本來運行perl腳本:故障使用C#

 String config_location = file_path 
     ProcessStartInfo perlStartInfo = new ProcessStartInfo(@"C:\Perl64\bin\perl.exe"); 


     perlStartInfo.Domain="C:\\e\\oa\\dir_path"; 
     perlStartInfo.FileName = "C:\\Perl64\\bin\\perl.exe"; 
     perlStartInfo.Arguments = "C:\\e\\oa\\Evergreen\\evg\\scripts\\helper\\program.pl" + "-config" + config_location; 
     perlStartInfo.UseShellExecute = false; 
     perlStartInfo.RedirectStandardOutput = false; 
     perlStartInfo.RedirectStandardError = false; 
     perlStartInfo.RedirectStandardInput = false; 
     perlStartInfo.CreateNoWindow = false; 
     perlStartInfo.WorkingDirectory="C:\\e\\oa\\dir_path"; 

     Process perl = new Process(); 
     perl.StartInfo = perlStartInfo; 
     perl.Start(); 
     perl.WaitForExit(); 

代碼已基本從這裏得到的 - https://social.msdn.microsoft.com/Forums/vstudio/en-US/ea9455e1-b254-49e1-99df-41718ea80b5b/how-to-run-perl-scripts-in-c

FILE_PATH一種說法到程序。 012irdir_path是程序應該查找它需要的數據的地方。 program.pl是我嘗試使用的perl腳本。

通過命令行運行腳本沒有問題。 使用我的代碼運行時 - 它看起來好像perl腳本根本不運行(我不知道),如果它確實和失敗我沒有得到程序的輸出。

回答

4

也許你錯過了參數中的空格?

perlStartInfo.Arguments = "C:\\e\\oa\\Evergreen\\evg\\scripts\\helper\\program.pl -config " + config_location; 
+0

它工作。簡直不敢相信。謝謝! – proton

+0

有一個隨機upvote推動你超過1000 ;-) – CupawnTae

+0

哈哈nice ty:D –