4

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

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's environment block
NULL,                // Use parent's starting directory
&si,                 // Pointer to STARTUPINFO structure
&pi                  // Pointer to PROCESS_INFORMATION structure
)  

Thanks for your help in advance.

ilent2
  • 5,171
  • 3
  • 21
  • 30
Destructor
  • 3,154
  • 7
  • 32
  • 51
  • Maybe this is what you are looking for. http://stackoverflow.com/questions/4743559/how-to-execute-child-console-programs-without-showing-the-console-window-from-th – Ivan Ishchenko Sep 17 '13 at 07:36

2 Answers2

0

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

Jonathan Potter
  • 36,172
  • 4
  • 64
  • 79
0

You have to redirect your output. There is a member hStdOutput and hStdError which should be redirected. Here on MSDN is an example.

bkausbk
  • 2,740
  • 1
  • 36
  • 52
  • could not figure it ! could tell me how exactly to do it? – Destructor Sep 17 '13 at 06:23
  • Please take a look at that example. There they show exactly what your are looking for. Bascily you have to specify another device handle for `hStdOutput` and/or `hStdError`. This can be a file handle to redirect everything to a file, or a pipe handle like in the example. You can also open the NUL device `CreateFile("nul"...)` to discard the output. – bkausbk Sep 17 '13 at 06:41