Skip to main content
 首页 » 编程设计

python之调用从 perl 返回值的 python 脚本

2025年05月04日7artech

我有一个 python 函数作为

import commands 
output=commands.getputput("ls -l") 
print output 
return output 

我需要从我的 perl 脚本中的 python 函数获取这个返回值

my($command)=`$python_script_path`; 
print $command; 

我的问题是,通过在 python 中打印输出,我可以在屏幕上得到我的结果,但我实际上也需要在 Perl 脚本中输出,所以我宁愿返回它。我怎样才能实现它? 另请注意,我不想使用内联 python。谢谢!!

请您参考如下方法:

commands模块自 2.6 起已弃用。使用 subprocess相反。

p = subprocess.Popen(['ls', '-l'], stdout=subprocess.PIPE, shell=True) 
print p.communicate()[0]