C#调用Perl脚本

  
/// <summary>
        /// Executes a process and waits for it to end. 
        /// </summary>
        /// <param name="fileName">Full Path of process to execute.</param>
        /// <param name="arguments">Command Line params of process</param>
        /// <param name="workingDirectory">Process working directory</param>
        /// <param name="timeout">Time to wait for process to end</param>
        /// <param name="stdOutput">Redirected standard output of process</param>
        /// <returns>Process exit code</returns>
        public static int ExecuteProcess(string fileName, string arguments, string workingDirectory, int timeout, out string stdOutput)
        {
            ProcessStartInfo psi = new ProcessStartInfo();

            psi.FileName = fileName;
            psi.Arguments = arguments;
            psi.WorkingDirectory = workingDirectory;
            psi.WindowStyle = ProcessWindowStyle.Hidden;
            psi.UseShellExecute = false;
            psi.RedirectStandardOutput = true;
            psi.CreateNoWindow = true;

            using (Process process = Process.Start(psi))
            {
                stdOutput = process.StandardOutput.ReadToEnd();

                process.WaitForExit(timeout);

                return process.ExitCode;
            }
        }


调用:

int exitCode = Util.ExecuteProcess("\"C:\\Perl\\bin\\perl.exe\"", " RouteGetter.pl ", "C:\\", 10000, out stdOutput);

ps:
第一个参数是 perl 的path路径,第二个参数是要调用perl文件的全称,第三个参数是被调用perl 文件的路径,第四个参数等待进程延迟时间,最后一个参数是返回的输出流。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值