c++ - mingw-w64 如何在打开外部应用程序时停止显示控制台

标签 c++ console launcher mingw-w64 app-launcher

我正在尝试编写一个应用程序来打开另一个应用程序并自行关闭,因此当外部应用程序打开时我不需要控制台

这是我到目前为止尝试过的:

system("cmd.exe /c application.exe"); //console shows, application opens, console wait

system("start \"\" application.exe"); //console shows, application opens, console close

//console does not show but neither the application (I can see it in task manager)
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
si.cb           = sizeof(si);
si.dwFlags      = STARTF_USESHOWWINDOW;
si.wShowWindow  = SW_HIDE;
ZeroMemory(&pi, sizeof(pi));
CreateProcess(0, "application.exe", 0, 0, FALSE, 0, 0, 0, &si, &pi);

//console does not show but neither the application (I can see it in task manager)
WinExec("application.exe", SW_HIDE);

这是我编译的方式:

g++ -o "launcher" "launcher.cpp" -mwindows

最佳答案

这是一些对我有用的代码来实现你的目标:

// Declare and initialize process blocks
PROCESS_INFORMATION processInformation;
STARTUPINFO startupInfo;

memset(&processInformation, 0, sizeof(processInformation));
memset(&startupInfo, 0, sizeof(startupInfo));
startupInfo.cb = sizeof(startupInfo);

// Call the executable program
TCHAR cmd[] =  myCommandText;

int result = ::CreateProcess(NULL, cmd, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS|CREATE_NO_WINDOW, NULL, NULL, &startupInfo, &processInformation);

在此上下文中,myCommandText 是一个控制台命令

关于c++ - mingw-w64 如何在打开外部应用程序时停止显示控制台,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24894507/

相关文章:

java - 所有移动制造商的启动器图标上的 Android 徽章编号

c++ - 如何在 Visual Studio 中签署控制台应用程序

c++ - 如何在程序中不使用分号的情况下打印分号(;)?

ios - 如何使用 os_log 在控制台应用程序中查看 iOS 设备日志

powershell - 搜索时的文件扩展名

postgresql - 类似 pgAdmin 的控制台软件

c++ - 没有匹配的函数来调用

c++ - C++实现哈希表时出现SIGSEGV错误

flutter - 为什么 flutter 在 url 启动器中给我 url null ?

c++ - C++ 二进制文件如何替换自身?