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)?
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.
CreateProcess; problem is,_popendo not pass these flags, so you have to use the Win32 APIs instead of_popento create your pipe.