0

我在使用 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])
4

1 回答 1

0

您可以使用 call 代替:

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

但是根据 JF 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

于 2013-05-19T20:34:24.610 回答