我正在使用Python的子进程模块来启动另一个程序。该程序需要参数'-c {0-7}'。Python子进程Popen不会将所有参数发送到shell
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)
在C++程序,我检查传入的参数:
for (int i = 0; i < argc; i++)
{
cerr << i << " " << argv[i] << endl;
}
cerr << "" << endl;
下面是当我运行python脚本输出:
[email protected]:~/embedded_pqa/saleae$ ./foobar.py -c3
Starting process: ['/home/user/code/foobar', '-c3']
0 /home/user/code/foobar
清楚地看出,参数'-c3'没有被传递给子进程。有什么想法吗?
像'strace'或'truss'的工具是看什么是真正的或没有被传递给'execve'系统调用正确的事情。另外,'shell = True'是邪恶的;如果你想控制你的参数如何传递,请不要使用它。 –