popen() doesn't behave as expected
Hi!
I'm writing a small program that allow the user to compile a C++ program, but the problem is that popen() works on the commented code Code:
//char *command="ls -l"; Code:
char *command="g++ /home/kim/Programming/QPort/hello.cpp -o /home/kim/Programming/QPort/hello"; Here is my code so far: Code:
void Simple::fileCompile() |
I tested whether your use of popen() was correct. Here's what I did:
Code:
wally:~/friday$ cat g.cpp 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. |
I have narrowed the problem to this line:
Code:
printf("%s", line); Why is the variable "line" empty even if the compiler failed? :scratch: |
Hi
It's because the error messages are sent to stderr, not stdout. And popen only read stdout. To get stderr when using popen, append 2>&1 to the command: char *command1="g++ /home/kim/Programming/QPort/hello.cpp -o /home/kim/Programming/QPort/hello 2>&1"; |
Thanks Guttorm! This solved my little problem. :)
|
All times are GMT -5. The time now is 11:03 PM. |