Python の subprocess モジュールを使用して別のプログラムを起動しています。プログラムには引数 '-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)
C++ プログラムでは、渡された引数をチェックしています。
for (int i = 0; i < argc; i++)
{
cerr << i << " " << argv[i] << endl;
}
cerr << "" << endl;
Pythonスクリプトを実行したときの出力は次のとおりです。
user@home:~/embedded_pqa/saleae$ ./foobar.py -c3
Starting process: ['/home/user/code/foobar', '-c3']
0 /home/user/code/foobar
明らかなように、引数「-c3」はサブプロセスに渡されていません。何かご意見は?