title: run a command that needs input without hanging, but still allow input
body: <p>I'm making a basic music player in C++ on an embedded Linux platform (Intel Edison). </p>
  
  <p>It works by sending commands to the shell to play the music using <code>mpg123</code>.</p>
  
  <p>Playing the music is working fine, but now I need to add media controls.  I'm using the <code>mpg123</code> command to play my MP3 files and if you pass it the <code>-C</code> flag then it listens for commands such as <code>p</code> for pause, <code>q</code> for quit, etc</p>
  
  <p>I'm using the code from this other SO answer for executing the commands <a href="https://stackoverflow.com/questions/478898/how-to-execute-a-command-and-get-output-of-command-within-c">How to execute a command and get output of command within C++ using POSIX?</a></p>
  
  <p>Now the thing is, when I run the command to play the selected song from c++ (eg. <code>mpg123 -C /media/sdcard/Music/&lt;songname&gt;</code>) it hangs the c++ program until the command returns, which doesn't return until the song is done playing. I can eliminate that issue by using <code>pthead</code> to run the command in a parallel thread, but that still doesn't allow me to enter commands as I need to. </p>
  
  <p>I thought of maybe somehow running the command in another <code>tty</code>, and then somehow passing the commands to <code>mpg123</code> by sending them to the other <code>tty</code>, but I was unable to find a way to do this. (and I'm not sure it's possable)</p>
  
  <p>I've been trying to do this for hours, so now I'm ready to ask here for some help :)</p>
  
  <p>Do any of you have any ideas on how to run the command without freezing the thread (in a pthread or whatever), and still be able to send commands to <code>mpg123</code>? </p>