<分区>
我正在尝试使用 c++ 中的系统命令。
std::string cmd = " DIR > d:\a.txt" ;
int isystemOut2 = system (cmd.c_str());
当我运行它时,我看到 d:\a.txt 有正确的输出,但我看到命令提示符立即打开和关闭。有没有办法阻止打开新的命令提示符。
<分区>
我正在尝试使用 c++ 中的系统命令。
std::string cmd = " DIR > d:\a.txt" ;
int isystemOut2 = system (cmd.c_str());
当我运行它时,我看到 d:\a.txt 有正确的输出,但我看到命令提示符立即打开和关闭。有没有办法阻止打开新的命令提示符。
最佳答案
您可以使用 Windows API 函数。例如CreateProcess .
STARTUPINFOW si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
if (CreateProcessW(cmd, arg, NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi))
{
WaitForSingleObject(pi.hProcess, INFINITE);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
关于c++ - C++ 中的系统调用打开一个新终端。 window ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48317275/