I am trying to execute a command line from my C code, but when I go to the fgets () function, I got a NULL error.
void executeCommand(char* cmd, char* output) { FILE *fcommand; char command_result[1000]; fcommand = popen(cmd, "r"); if (fcommand == NULL) { printf("Fail: %s\n", cmd); } else { if (fgets(command_result, (sizeof(command_result)-1), fcommand) == NULL) printf("Error !"); strcpy(output, command_result); } pclose(fcommand); }
And my team:
java -jar <parameters>
Why do I have a NULL result from fgets, even though when I try to execute the same command in the terminal, it works as expected.
source share