Hide console window when running command via C ++

I used CreateProcess to run the command and used the CREATE_NO_WINDOW flag, but the console pops up for a fraction of a second, how to avoid this?

STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); ZeroMemory( &pi, sizeof(pi) ); CreateProcess ( NULL, // No module name (use command line) command, //set env variable and use it is my command NULL, // Process handle not inheritable NULL, // Thread handle not inheritable FALSE, // Set handle inheritance to FALSE CREATE_NO_WINDOW, //don't create window but it appears for fraction of second! NULL, // Use parent environment block NULL, // Use parent starting directory &si, // Pointer to STARTUPINFO structure &pi // Pointer to PROCESS_INFORMATION structure ) 

Thanks for your help in advance.

+4
source share
2 answers

You must redirect your output. There is a member of hStdOutput and hStdError that must be redirected. Here is an example of MSDN .

0
source

In the STARTUPINFO structure STARTUPINFO set the STARTF_USESHOWWINDOW flag in the dwFlags member and set wShowWindow to SW_HIDE .

0
source

Source: https://habr.com/ru/post/1502540/


All Articles