Как перехватить exit_code и stderr команды, которая запускается в C ++?
Я пишу программу на С ++, которая выполняет и выводит (в режиме реального времени) сценарий оболочки, make-файл или просто другую программу. Однако я хотел бы, чтобы моя программа возвращалась по-другому, когда есть ошибки или нет ошибок.
#include "execxi.h"
using namespace std;
int execXI::run(string command)
{
FILE *in;
char buff[512];
// is this the check for command execution exited with not 0?
if(!(in = popen(command.c_str(), "r"))){
// I want to return the exit code and error message too if any
return 1;
}
// this part echoes the output of the command that's executed
while(fgets(buff, sizeof(buff), in)!=NULL){
cout < buff;
}
pclose(in);
return 0;
}