简体   繁体   中英

c++ system command

I have written a sample c++ program...here i am using system command to call python program with an argument...

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 is a parameter for this program.

but I am getting error as:

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

You can also do it this way:

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);

if you want to do it in the same style.

Say this:

#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());

look at the end of the arguments you are passing in to the function

... ,tid);

if you are trying to format a string? Do it before you use it as an argument.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM