i'm trying to pipe to another program on OS X with C to run a command and get results. The problem i'm having is that when the popen() function runs, the program it targets just prints results to the terminal connected to my IDE instead of the pipe which i opened.
Here's the test program
void checkcmdline(void) {
FILE* pipe;
pipe = popen("vcpkg", "r");
while (!feof(pipe)) {
int32_t c;
c = fgetc(pipe);
fprintf(stdout, "Character read from the pipe is %c.\r\n", (char)c);
}
pclose(pipe);
}
When it runs this is printed to the terminal of xcode
sh: vcpkg: command not found
Character read from the pipe is \377.
Program ended with exit code: 0
See that line 1 is the results of the popen("vcpkg", "r") function, instead of being read inside the loop it just gets printed straight to the terminal. Anyone know why this is happening?