C:无论如何将参数加载到system()调用中

问题描述 投票:2回答:2

是否可以在系统调用中放入参数?

就像是

system("rm %s %s", string1, string2)
c variables arguments system
2个回答
9
投票

system函数的原型是:

int system(const char *command);

所以不行。但是,怎么样:

snprintf(buffer, sizeof(buffer), "rm %s %s", target1, target2);
system(buffer);

0
投票

试试这个:

private:    
char command[128];
char temp[10] = {'"','I','P','v','4','"'}; //snprintf();
public:
int SysInfo(){
    snprintf(command,sizeof(command), "ipconfig | find  %s > save.log",temp);
    system(command);
}
© www.soinside.com 2019 - 2024. All rights reserved.