How do I convert argv to lpCommandLine parameter of CreateProcess?

后端 未结 4 629
深忆病人
深忆病人 2021-01-29 14:37

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         


        
4条回答
  •  不思量自难忘°
    2021-01-29 15:13

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

提交回复
热议问题