Dasser Basyouni Dasser Basyouni - 6 months ago 45
C Question

what kinds of errors popen record

I am trying to execute the command

"adb tcpip 5555"
in cmd and get the output to use it in another statement.

This adb code should give
error: no devices/emulators found
but the buffer remains empty.

FILE* lsofFile_p = popen("c:\\adb tcpip 5555" ,"r");
char* line_p = fgets(buffer, sizeof(buffer), lsofFile_p);
printf("\n***\nbuffer = %s***\n\n", buffer);
printf("\n***\nbuffer = %s***\n\n", buffer);

usr usr

popen() returns FILE* to the stdout of the command you run. So, if you want to read stderr (it looks like the command you run gives errors that goes to stderr), then you could do redirect stderr to stdout:

FILE* lsofFile_p = popen("c:\\adb tcpip 5555 2>&1" ,"r");

Be aware that this will mix stdout and stderr. So, there's no way to differentiate output and errors, if that matters.