Perl文件1.pl:
#!/usr/local/bin/perl -w
($b) = @ARGV;
$a = 1;
$c = $a + $b;
print "$c\n";
exit;
python文件1.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
import subprocess
b = 2
res = subprocess.call(["perl", "1.pl", str(b)])
print res
签出
$python 1.py
输出:
3
0
输出应为3,这怎么了?
0
是returncode属性。
$perl so.pl 2
3
$ echo $?
0 #this gets stored in `res`
只需使用:
subprocess.call(["perl", "1.pl", str(b)])
如果您不想0
在输出中使用。
您也subprocess.check_output
可以将命令的输出存储在变量中。
>>> res = subprocess.check_output(["perl", "so.pl", '2'])
>>> print res
3
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句