I'd like to be able to get output from a program the way some (most) IDEs can get the error messages that compilers like GCC output. I can't think of any way to do this.
In the example, b should output "Hello, world!\n" too. How can I do this?
Finally, does it make it harder if a is a Python script?
Thanks.
By the way, I realise it's not going to be anywhere near as simple as that (although I can't imagine it's incredibly difficult).
I've thought about writing the text to a file, then opening it with the C++ program and printing the contents, then closing the file and deleting it. I guess that would work... but it means alot of modifying...
1. Create pipe.
2. fork().
3. In child process:
a. close stdout and stderr
b. dup2 the pipe to stdout and stderr
c. close read end of pipe
d. exec the new program
4. In parent process:
a. close write end of pipe
b. read from the read end of pipe.