运行cmd.exe时,加了/c参数后它将运行/c后面的命令,不加参数的话,它只执行CMD命令。
system("xxx"),相当于执行cmd.exe /c xxx。
使用WinExec或ShellExecute和cmd.exe /c 来达到隐藏窗口的目的。
示例:
WinExec("cmd.exe /c dir > d:\\abc.txt", SW_HIDE);
ShellExecute(nullptr, L"open", L"cmd.exe", L"/c dir > d:\\abc.txt", nullptr, SW_HIDE);