2012-08-24 157 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); 

,如果你想這樣做在同一樣式。