I tested whether your use of
popen() was correct. Here's what I did:
Code:
wally:~/friday$ cat g.cpp
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE *fpipe;
//char *command="ls -l";
char *command1="g++ /home/kim/Programming/QPort/hello.cpp -o /home/kim/Programming/QPort/hello";
char *command2="g++ h.cpp -o h";
char line[256];
if ( !(fpipe = (FILE*)popen(command1,"r")) )
{ // If fpipe is NULL
perror("Problems with pipe");
exit(1);
}
while ( fgets( line, sizeof line, fpipe))
{
printf("%s", line);
}
pclose(fpipe);
if ( !(fpipe = (FILE*)popen(command2,"r")) )
{ // If fpipe is NULL
perror("Problems with pipe");
exit(1);
}
while ( fgets( line, sizeof line, fpipe))
{
printf("%s", line);
}
pclose(fpipe);
}
wally:~/friday$ g++ g.cpp -o g
wally:~/friday$ ls
f.cpp g g.cpp h.cpp typescript
wally:~/friday$ g
g++: /home/kim/Programming/QPort/hello.cpp: No such file or directory
g++: no input files
wally:~/friday$ ls
f.cpp g g.cpp h h.cpp typescript
wally:~/friday$ # Note that the file "h" has appeared.
wally:~/friday$
Everything worked. It ain't
popen().
Edit:
Owe. Weight. You wanted "compiler output" perhaps to the screen?
If the compile goes perfectly well, the compiler doesn't send anything to standard output or standard error. That's why the file
h "silently" appeared after running the above compile.
Hope this helps.