I set the flag - CREATE_NEW_CONSOLE in the CreateProcess attributes, but when debugging, the new console is not displayed. The task itself: Create a child process Child (add another console view of the project to the workspace, when creating a child process, take the new console to it).

 int main(int argc, char *argv[], char *envp[]) { //Создание дочернего процесса STARTUPINFO si = { sizeof(si) }; SECURITY_ATTRIBUTES saProcess, saThread; PROCESS_INFORMATION piProcessB; TCHAR szPath[MAX_PATH]; lstrcpy(szPath, TEXT("Parents")); CreateProcess(NULL, szPath, &saProcess, &saThread, FALSE, NULL, NULL, NULL, &si, &piProcessB); saProcess.nLength = sizeof(saProcess); saProcess.lpSecurityDescriptor = NULL; saProcess.bInheritHandle = TRUE; saThread.nLength = sizeof(saThread); saThread.lpSecurityDescriptor = NULL; saThread.bInheritHandle = FALSE; lstrcpy(szPath, TEXT("Child")); CreateProcess(NULL, szPath, &saProcess, &saThread, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &piProcessB); GetLastError(); getch(); } 

    1 answer 1

    The console must order the child process itself. (The easiest way to do this is to compile it as a console application, the console will appear automatically.) You will not be able to make it appear with start flags. For example, no matter how you run Notepad.exe, the console will not appear.

    The CREATE_NEW_CONSOLE flag does not quite what you think. It simply means that if the application being launched orders the console window itself, this window should not be inherited from your process (as happens if you run, for example, command line utilities from under cmd.exe), but created again (there will be two windows). Here it is.


    Addition: your question says that you compile child yourself. Then do this:

    • Make sure you compile it as a console application.
    • Make sure that the process starts without errors. Do not ignore the return value of the CreateProcess and GetLastError functions!
    • Print any line in the main function of the child program and see which console it is displayed in.
    • @VladD, then what can be done to bring out a new console for "Child"? - AlexC
    • @AlexC: if Child is your program, then just compile it as a console application. If not yours, nothing can be done. - VladD
    • @VladD Run cmd.exe, and Child - into parameters, along with the /C cmd.exe / C Child key /C If you have not forgotten. Winds are not at hand. - alexlz
    • one
      > If not yours, nothing can be done. Not quite right. You can change the subsystem on the console in the PE header, then when you start the same notebook, the console window will also appear, but of course nothing will be written to this console. - insolor
    • one
      @insolor i.e. Do they quite agree to make a reverse exchange? Russified into the original? - alexlz