Let I want to write an application, that launches another application. Like this:
# This will launch another_app.exe
my_app.exe another_app.exe
# This will laun
You need to recreate the command line, taking care of having all program name and arguments enclosed in "
. This is done by concatenating a \"
to these strings, one at the beginning, one at the end.
Assuming the program name to be created is argv[1]
, the first argument argv[2]
etc...
char command[1024]; // size to be adjusted
int i;
for (*command=0, i=1 ; i 1) strcat(command, " ");
strcat(command, "\"");
strcat(command, argv[i]);
strcat(command, "\"");
}
Use the 2nd argument of CreateProcess
CreateProcess(NULL, command, ...);