如何从Perl调用python脚本? [英] How to call a python script from Perl?

查看:193
本文介绍了如何从Perl调用python脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要用Perl脚本中很少的参数调用"/usr/bin/pdf2txt.py".我该怎么办?

I need to call "/usr/bin/pdf2txt.py" with few arguments from my Perl script. How should i do this ?

推荐答案

如果您需要捕获 STDOUT :

my $ret = `/usr/bin/pdf2txt.py arg1 arg2`;

您可以轻松捕获 STDERR ,将其重定向到STDOUT:

You can easily capture STDERR redirecting it to STDOUT:

my $ret = `/usr/bin/pdf2txt.py arg1 arg2 2>&1`;

如果您需要获取退出状态,则可以使用:

If you need to capture the exit status, then you can use:

my $ret = system("/usr/bin/pdf2txt.py arg1 arg2");

请记住, `` system() 块,直到程序完成执行.

Take in mind that both `` and system() block until the program finishes execution.

如果您不想等待,或者需要同时捕获STDOUT/STDERR和退出状态,则应使用 IPC :: Open3 .

If you don't want to wait, or you need to capture both STDOUT/STDERR and exit status, then you should use IPC::Open3.

这篇关于如何从Perl调用python脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆