在linux上运行python2.7中的二进制文件

时间:2013-05-19 20:27:24

标签: python subprocess

我在使用Popen传递多个变量时在python中运行外部程序时出现问题:

#!/usr/bin/env python
import sys
import os
import shlex, subprocess

a = raw_input("Enter a number:")
b = raw_input("Enter a file:")
c = raw_input("Enter dir to search:")

subprocess.Popen(['/bin/sh', "./catnum.bin", "-m",  a, "--remove",  "-o results.txt", b, c])

1 个答案:

答案 0 :(得分:0)

您可以改用呼叫:

from subprocess import call
call(["cactnum.bin", "-m",a, "--remove",  "-o results.txt", b, c])

但根据J.F. Sebastian的评论

真正的问题是invalid/unnecessary /bin/sh call b) "-o results.txt"应该写成"-o", "results.txt"(2 args),即正确的调用是:subprocess.check_call(["./catnum.bin", "-m", a, "--remove", "-o", "results.txt", b, c]) if catnum.bin is executable