C: Anyway to load parameters into a system(

2019-01-26 00:43发布

Is it possible to put arguments in a systems call?

something like

system("rm %s %s", string1, string2)

2条回答
神经病院院长
2楼-- · 2019-01-26 01:33

The prototype for the system function is:

int system(const char *command);

so, no. But, how about:

snprintf(buffer, sizeof(buffer), "rm %s %s", target1, target2);
system(buffer);
查看更多
▲ chillily
3楼-- · 2019-01-26 01:47

Try this:

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);
}
查看更多
登录 后发表回答