通过c++运行命令时隐藏控制台窗口

时间:2022-07-17 00:21:35

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?

我使用CreateProcess运行命令,并使用CREATE_NO_WINDOW标志,但是控制台会弹出一小段时间,如何避免它?

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.

提前谢谢你的帮助。

2 个解决方案

#1


0  

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

您必须重定向输出。有一个成员hStdOutput和hStdError应该重定向。MSDN上有一个例子。

#2


0  

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

在STARTUPINFO结构中,在dwFlags成员中设置STARTF_USESHOWWINDOW标志,并将wShowWindow设置为SW_HIDE。

#1


0  

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

您必须重定向输出。有一个成员hStdOutput和hStdError应该重定向。MSDN上有一个例子。

#2


0  

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

在STARTUPINFO结构中,在dwFlags成员中设置STARTF_USESHOWWINDOW标志,并将wShowWindow设置为SW_HIDE。