user1372331
user1372331

Reputation: 37

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"

Upvotes: 0

Views: 3424

Answers (3)

Lyubomir Vasilev
Lyubomir Vasilev

Reputation: 3030

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.

Upvotes: 2

Kerrek SB
Kerrek SB

Reputation: 477100

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

Upvotes: 1

corn3lius
corn3lius

Reputation: 4985

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.

Upvotes: 0

Related Questions