2012-08-24 159 views
1

我已经写了一个C++程序......在这里我使用系统命令来调用Python程序与参数...C++系统命令

system("python /home/rpms/a3/dsp/noise_rem_python.py /home/rpms/a3/dsp/files/p1f%d.txt",tid); 

/home/rpms/a3/dsp/noise_rem_python.py is a program name 

/home/rpms/a3/dsp/files/p1f%d.txt这个程序的参数。

,但我得到的错误是:

"/usr/include/stdlib.h: In function ‘void* writefile(void*)’: /usr/include/stdlib.h:712: error: too many arguments to function ‘int system(const char*)’ writefile.cpp:29: error: at this point in file"

+2

什么是tid); ? – BSen

+1

C++并不神奇。如果空气稀薄,它不会为你排列一个字符串。 –

回答

0

看看你正在传递给函数

的参数的结尾......,TID);

如果你想格式化一个字符串?在你用它作为参数之前做这件事。

1

这样说:

#include <string> 

system(("python /home/rpms/a3/dsp/noise_rem_python.py /home/rpms/a3/dsp/files/p1f" + std::to_string(tid) + ".txt").c_str()); 
+0

你错过了一个开头'('围绕字符串表达式 –

+0

@JamesKanze:谢谢,修正!我原本在第一部分有一个'std :: string',但实际上并不需要。 –

+0

'std :: to_string ()'只是C++ 11,我们不知道OP是否可以使用它 –

2

你也可以这样来做:

char command[200]; // 200 is just an example value that can hold the whole string 
sprintf(command, "python /home/rpms/a3/dsp/noise_rem_python.py /home/rpms/a3/dsp/files/p1f%d.txt", tid); 
system(command); 

,如果你想这样做在同一样式。