Can't call system with white space in parameter

84 views Asked by At

I'm trying to make this system call work. it works in case there is no space in address, but it doesn't work if there's a space in address...

this call copies a file from one place to another.

how to escape space in this code properly?

char buffer[300];
snprintf(buffer, sizeof(buffer), "copy %s\\%s %s", AssistPath, apiFileName, path);
system(buffer);
2

There are 2 answers

7
ikh On

Space is matter? Then why don't you try this code?

snprintf(buffer, sizeof(buffer), "copy \"%s\\%s\" \"%s\"", AssistPath, apiFileName, path);
0
ojblass On

You can probably use quotes around the things that may have spaces

"copy \"%s\\%s\" \"%s\""