I'm having issues running a external program in python using Popen to pass multiple variables:
#!/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])
You could use call instead:
from subprocess import call
call(["cactnum.bin", "-m",a, "--remove", "-o results.txt", b, c])
However per the comment of JF Sebastian
The real issue is invalid/unnecessary /bin/sh call b) "-o results.txt"
should be written as "-o", "results.txt"
(2 args) ie, the correct call is: subprocess.check_call(["./catnum.bin", "-m", a, "--remove", "-o", "results.txt", b, c]) if catnum.bin is executable
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.