I have searched many and read many codes but I do not understand why is the variable(the cmd output) can not be printed to be sure of it
the question might be repetitive but I can not comment on any code I saw as I am below 50 reputation
here is the code I am trying and I am trying to get the output of the cmd and use it in IF statement so of example if it gives error then resend the command
int main(int argc, char *argv)
FILE *lsofFile_p = popen("adb reboot", "r");
char *line_p = fgets(buffer, sizeof(buffer), lsofFile_p);
This only prints two
\n. That's it. Not more, not less. That's why you think that it prints "nothing". Also note that
*lsofFile_p is undefined behavior because you closed the file the line before, and this invalidates the file pointer.
You probably want to print the line that you read from
lsofFile_p, which you stored in
//'%s' take the second argument of printf and interprets it as a string printf("%s\n\n", buffer);
std::cout, and other facilities to make your life easier, you don't have to program in C when you are programming in C++.