C++ popen command without console

后端 未结 4 1187
借酒劲吻你
借酒劲吻你 2020-12-20 17:20

when I use popen to get the output of a command, say dir, it will prompt out a console.

however, can I get the output of a command without the appearance of the cons

4条回答
  •  情书的邮戳
    2020-12-20 17:24

    I needed to solve this for my full screen OpenGL Windows application, but was unable to prevent the console window popping up. Instead, taking back focus after a short delay seems to work well enough to avoid seeing it.

    _popen(cmd, "wb");
    
    Sleep(100);
    
    ShowWindow(hWnd, SW_SHOWDEFAULT);
    SetForegroundWindow(hWnd);
    

    Update: this apparently doesn't work if the program is launched from Explorer. It is working when launched from Visual Studio.

提交回复
热议问题