0
output = cStringIO.StringIO()
output.write('string') # this emulates some_file.txt
p = subprocess.Popen(['perl', 'file.pl'], shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
line, _ = p.communicate(output.getvalue())
print line
output.close()
这打印Can't open perl script "file.pl": No such file or directory
。 python脚本和perl文件在同一个目录下!获取`perl file.pl <some_file.txt` shell命令的输出
我想line
是的perl file.pl < some_file.txt
输出如何做到这一点?
是在当前工作目录中的file.pl? –
@ ChadS.Yes,它在同一个目录中。我已经更新了这个问题。 –
你的问题似乎与'subprocess'和'cStringIO'没有任何关系。尝试指定'file.pl'的绝对路径。 – martineau