Chris Allen
Chris Allen

Reputation: 703

C: Anyway to load parameters into a system() call

Is it possible to put arguments in a systems call?

something like

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

Upvotes: 3

Views: 16350

Answers (2)

n0va_sa
n0va_sa

Reputation: 19

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

Upvotes: -1

Michael F
Michael F

Reputation: 40830

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

Upvotes: 11

Related Questions