Is there any way of stopping _popen opening a dos window?

c++, popen, shell, windows

Solution

As far as I know, you can't1: you are starting a console application (cmd.exe, that will run the specified command), and Windows always creates a console window when starting a console application.

- although, you can hide the window after the process started, or even create it hidden if you pass the appropriate flags to `CreateProcess`; problem is, `_popen` do not pass these flags, so you have to use the Win32 APIs instead of `_popen` to create your pipe.

Problem

I am using _popen to start a process to run a command and gather the output This is my c++ code: ``` bool exec(string &cmd, string &result) { result = ""; FILE* pipe = _popen(cmd.c_str(), "rt"); if (!pipe) return(false); char buffer[128]; while(!feof(pipe)) { if(fgets(buffer, 128, pipe) != NULL) result += buffer; } _pclose(pipe); return(true); } ``` Is there any way of doing this without a console window opening (as it currently does at the _popen statement)?

Original source

Related problems