简体   繁体   English

c ++系统命令

[英]c++ system command

I have written a sample c++ program...here i am using system command to call python program with an argument... 我已经编写了一个示例c ++程序...这里我使用系统命令来调用带有参数的python程序...

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. /home/rpms/a3/dsp/files/p1f%d.txt是此程序的参数。

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" “/usr/include/stdlib.h:在函数'void * writefile(void *)'中:/ usr / include / stdlib.h:712:错误:函数'int system(const char *)'writefile的参数太多.cpp:29:错误:此时在文件中“

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); ...,tid);

if you are trying to format a string? 如果你想格式化一个字符串? Do it before you use it as an argument. 在你用它作为一个参数之前做它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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