c++系统命令

c++ system command

本文关键字:系统命令 c++      更新时间:2023-10-16

我已经编写了一个示例c++程序。。。在这里,我使用system命令调用带有参数的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是该程序的一个参数。

但我得到的错误是:

"/usr/include/stdlib.h:在函数'void*writefile(void*)'中:/usr/include/stdlib.h:712:错误:函数"int system(const char*)"的参数太多writefile.cpp:29:错误:此时在文件""中

您也可以这样做:

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

如果你想用同样的风格来做。

这样说:

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

查看传递给函数的参数的末尾

tid);

如果您正在尝试格式化字符串?在把它用作论据之前先做一下。