chouaib23 chouaib23 - 3 months ago 15
C Question

Too many arguments in system() call

I have a problem with arguments in the

system()
call in C.

Code:



char macaddr[13];
uint8_t mac[6];
memset(macaddr, '\0', 13);
mac_get_ascii_from_file("/sys/class/net/eth0/address", macaddr);

system("rm /var/tuxbox/config/cxx.bin");
system("wget -P /var/tuxbox/config http://xxxxxxx/xx/cxx_%s.bin\n", macaddr);


Error message:




too many arguments to function 'system'

Answer

system() doesn't handle printf style arguments. You need to build the command string up first and then pass it to system.

e.g.

char cmd[512];
sprintf(cmd, "wget -P /var/tuxbox/config http://xxxxxxx/xx/cxx_%s.bin\n", macaddr);
// or snprintf(cmd, sizeof(cmd), "wget...
system(cmd);

(note, no error handling etc included.)

Comments