2012-08-24 2 views
1

나는 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

이 프로그램에 대한 매개 변수입니다 ... 여기에 내가 인수로 파이썬 프로그램을 호출하는 시스템 명령을 사용하고 ... 샘플 C++ 프로그램을 작성했습니다.) TID, ... 당신이 기능

에 전달하는 인수의 끝에

"/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

보기;

하지만 난 같은 오류를 얻고있다

문자열을 포맷하려는 경우? 인수로 사용하기 전에 수행하십시오.

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 주위에 개방'('이 누락 :.!. 덕분에, 고정을 내가 원래 첫 번째 부분 주위에'표준 : string'을 가지고 있지만, 실제로 필요하지 않은 것 –

+0

'표준 : to_string()'는 C++ 11에서만 사용할 수 있습니다 .OK가 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); 

이 같은 스타일을 수행하려는 경우.