小编Rus*_*sty的帖子

Python子进程Popen没有向shell发送所有参数

我正在使用Python的子进程模块来启动另一个程序.该程序需要一个参数'-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)
Run Code Online (Sandbox Code Playgroud)

在C++程序中,我正在检查传入的参数:

for (int i = 0; i < argc; i++)
{   
    cerr << i << "   " << argv[i] << endl;
}   
cerr << "" << endl;
Run Code Online (Sandbox Code Playgroud)

这是我运行python脚本时的输出:

user@home:~/embedded_pqa/saleae$ ./foobar.py -c3
Starting process: ['/home/user/code/foobar', '-c3']
0   /home/user/code/foobar
Run Code Online (Sandbox Code Playgroud)

很明显,参数'-c3'没有传递给子进程.有什么想法吗?

python subprocess popen

2
推荐指数
1
解决办法
1853
查看次数

标签 统计

popen ×1

python ×1

subprocess ×1