I am using Python's subprocess module to launch another program. The program requires an argument '-c{0-7}'.
this_dir = os.path.dirname(os.path.abspath(__file__))
cmd = [os.path.join(this_dir,'foobar'),'-c%d' % channel]
print "Starting process: %s" % str(cmd)
Proc = subprocess.Popen(cmd,stdout=subprocess.PIPE,shell=True)
In the C++ program, I'm checking the arguments passed in:
for (int i = 0; i < argc; i++)
{
cerr << i << " " << argv[i] << endl;
}
cerr << "" << endl;
Here is the output when I run the python script:
user@home:~/embedded_pqa/saleae$ ./foobar.py -c3
Starting process: ['/home/user/code/foobar', '-c3']
0 /home/user/code/foobar
As is clear, the argument '-c3' is not being passed to the subprocess. Any thoughts?
straceortrussis the right thing to see what actually is or isn't being passed to theexecvesyscall. Also,shell=Trueis evil; if you want control of how your arguments are passed, don't use it.