0

I am running a 'flute' (a protocol for sending multicast traffic) application/binary (which I downloaded) from C program by popen(). This application has a feature/bug that it doesn't run in background, since it uses the shell to take some commands. And during the run, the application locks the shell. That means you can only type some pre-defined letters in the shell, otherwise you have to wait till the end. So, when I run multiple instances of the application using popen() from c code, the shell hangs permanently, probably because both applications tries to use it simultaneously (my assumption). But I can manually run multiple instances in different shells. Here is the sample code to run it from C program.

FILE* pF = popen("./flute -send -a226.0.0.1/6789 /media/song.mp3", "r");

Is there any solution so that the shell doesn't hang. Please help.

JatiA
  • 73
  • 1
  • 4
  • 12

1 Answers1

1

If the process is just hanging because it wrote a prompt to your pF and is now blocked reading from the inherited stdin, you could:

  • forward the prompt read from pF to stdout so it shows up on the terminal - then you'll know when/what to type
  • or manually fork and intercept both stdin and stdout: then the prompt won't go to your terminal, and your program can send the "pre-defined letters" programmatically

If the process is hanging because it's really doing something with the inherited terminal, you can create a pseudoterminal for each child process, so they're not messing with the same controlling terminal. See this question for reference.

Community
  • 1
  • 1
Useless
  • 64,155
  • 6
  • 88
  • 132
  • Thanks for the answer. Can you just explain your first point a little bit? I could not understand it properly. – JatiA Oct 20 '14 at 10:30
  • read the child process' output from your popen `FILE*`, and write whatever you get to `stdout`. Then, you'll be able to see what the child process is doing (or asking for) on the terminal. – Useless Oct 20 '14 at 13:17