[英]AllocConsole() with hidden console window
I'm trying to launch bash.exe, running in interactive mode, as a child process. 我试图启动以交互模式运行的bash.exe作为子进程。 The only way I have found to do this is to launch bash.exe from a console program, or to AllocConsole() to a non-console program and then launch it.
我发现执行此操作的唯一方法是从控制台程序启动bash.exe,或将AllashConsole()启动到非控制台程序,然后启动它。 It seems that if it isn't launched from a console program, or at least a program which has been allocated a console, bash.exe refuses to launch in interactive mode.
看来,如果它不是从控制台程序启动的,或者至少不是从已分配控制台的程序启动的,则bash.exe拒绝以交互方式启动。
Since the base program has to be a GUI program, I have to use AllocConsole. 由于基本程序必须是GUI程序,因此我必须使用AllocConsole。 However, if I do so, this creates a visible console.
但是,如果这样做,则会创建一个可见的控制台。 That won't be acceptable for the program I'm building.
对于我正在构建的程序,这是不可接受的。
I know how to create hidden child processes, but the console popping up comes from AllocConsole, not CreateProcess. 我知道如何创建隐藏的子进程,但是弹出的控制台来自AllocConsole,而不是CreateProcess。 There are a number of questions like this, but most of them end with workarounds, and it seems like my situation precludes all the workarounds I can find.
有很多这样的问题,但是大多数问题都以解决方法结束,看来我的处境妨碍了我能找到的所有解决方法。
How can I use AllocConsole without a console appearing? 如何在没有控制台的情况下使用AllocConsole? Failing that, how can I launch bash.exe as a child process of a GUI program, in interactive mode, without using AllocConsole?
失败了,如何在不使用AllocConsole的情况下以交互方式将bash.exe作为GUI程序的子进程启动?
eryksun's approach worked. eryksun的方法奏效了。 I launch the process with the following settings.
我使用以下设置启动该过程。 I can then use AttachConsole and FreeConsole with the processId to manipulate the console.
然后,我可以将AttachConsole和FreeConsole与processId一起使用来操纵控制台。
siStartInfo.wShowWindow = SW_HIDE;
siStartInfo.dwFlags = STARTF_USESHOWWINDOW;
BOOL success = CreateProcess(
applicationAddress, // absolute path to the application
TEXT("-i"), // command line
NULL, // process security attributes
NULL, // primary thread security attributes
TRUE, // handles are inherited
CREATE_NEW_CONSOLE, // creation flags
NULL, // use parent's environment
NULL, // use parent's current directory
&siStartInfo, // STARTUPINFO pointer
&piProcInfo); // receives PROCESS_INFORMATION
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.