从代码Exception运行perl脚本

时间:2013-02-27 15:24:10

标签: c# perl

我使用了以下代码:

static void Main(string[] args)
    {
        ProcessStartInfo perlStartInfo = new ProcessStartInfo(@"C:\strawberry\perl\bin\perl.exe");
        perlStartInfo.Arguments = "c:\\ebm\\parse_ebm_log.pl";
        perlStartInfo.UseShellExecute = false;
        perlStartInfo.RedirectStandardOutput = true;
        perlStartInfo.RedirectStandardError = true;
        perlStartInfo.CreateNoWindow = false;

        Process perl = new Process();
        perl.StartInfo = perlStartInfo;
        perl.Start();
        perl.WaitForExit();
        string output = perl.StandardOutput.ReadToEnd();
    }

现在,当我查看perl.MainModule时,我有这个异常: MainModule ='perl.MainModule'引发了类型

的异常
  

'System.ComponentModel.Win32Exception'base {System.SystemException} =   {“只有ReadProcessMemory或WriteProcessMemory请求的一部分   完成了“}

目标构建是x64,因为在同一个perl.MainModule中有先前异常,因为它表示无法在x32进程上运行x64(类似的东西)

1 个答案:

答案 0 :(得分:1)

尝试在PATH环境中添加perl(之后打开一个新的Windows shell)以及下面的更改

ProcessStartInfo perlStartInfo = new ProcessStartInfo()
perlStartInfo.FileName= "perl.exe"
perlStartInfo.UseShellExecute = true