1

I am making a simple bash terminal with the SFML framework for C++. I understand how to begin an external process with the system() fn, but I need a way to stream a child process's output into the current script. Is there a simple way to do this? Perhaps using an fstream hack? I am using Unix.

3
  • Which OS? There's popen on linux that might do what you want Commented Mar 1, 2012 at 21:01
  • It is a POSIX function, not only on Linux. ;-) Commented Mar 1, 2012 at 21:04
  • 1
    @DejanLekic I'd rather be safe than sorry :) All I can claim is that it's on my linux OS, but thanks for the correction! Commented Mar 1, 2012 at 21:08

1 Answer 1

2

You need to use pipe()s - . The basic idea is to fork() then to dup2() the file descriptors 0 (stdin), 1 (stdout) and, respectively, 2 (stderr) into the specific pipes and then to waitpid() in your "main" branch of the fork until you get an WIFEXITED on the "child" branch.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.