Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/127.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 生成控制台窗口而不锁定应用程序_C++_Visual C++ - Fatal编程技术网

C++ 生成控制台窗口而不锁定应用程序

C++ 生成控制台窗口而不锁定应用程序,c++,visual-c++,C++,Visual C++,我正在尝试生成一个控制台窗口,以便根据用户选择的一些数据从我的应用程序运行另一个可执行文件。这是一个非常简单的设置现在 std::string command; { command += "\"" + INSTALL_DIR + "export.exe\""; command += " -id " + processID; } system(command.c_str()); 问题是导出可能需要一个小时或更长时间,我不想锁定应用程序。我曾经提到,在命令末尾使用“&”可以实现这

我正在尝试生成一个控制台窗口,以便根据用户选择的一些数据从我的应用程序运行另一个可执行文件。这是一个非常简单的设置现在

std::string command;
{
    command += "\"" + INSTALL_DIR + "export.exe\"";
    command += " -id " +  processID;
}
system(command.c_str());
问题是导出可能需要一个小时或更长时间,我不想锁定应用程序。我曾经提到,在命令末尾使用“&”可以实现这一点(比如:“c:\some\path\export.exe-id 19998&”),但它对我不起作用

任何帮助都将不胜感激

问题是导出可能需要一个小时或更长时间,我不想锁定应用程序

调用将同步执行并阻止调用线程,直到完成

寻找直接与winapi交互,或使用家族中的函数生成异步运行的子进程


另一个(可移植)解决方案是在应用程序中使用单独的,它发出
system()
调用:

std::string command;
command += "\"" + INSTALL_DIR + "export.exe\"";
command += " -id " +  processID;

std::thread t([](const std::string& command){
        system(command.c_str());
    }, command);
std::cout << "main thread" << std::endl;

&在shell中工作(命令提示)。您应该做的是使用
CreateThread
或使用C++11
std::thread
创建一个新线程,并从那里调用新命令。但是我建议不要使用system命令:

Adding&仅适用于*nix系统。即使在system命令中,bash也会解释&。我会使用
t.join();