-2

This question already has an answer here:

I have two programs foo.sh and bar.sh both of which contain infite loops, produce continuous Output and should run in parallel. I would like to pipe the output of both those programs to a third program consumer.

Initially I only had foo.sh running and the piping was easy via

./foo.sh | ./consumer

But now I would like to add bar.sh to also send its output to consumer.

I have tried the things suggested in those answers (Answer 1, Answer 2) but they only seem to work for programs where one ends and the next gets started after the first one ends. I need them both to run in parallel.

This does not work, as it only pipes the output of foo.sh and never starts bar.sh:

( ./foo.sh ; ./bar.sh ) | ./consumer

This lucky guess gave me a syntax error:

( ./foo.sh & ; ./bar.sh & ) | ./consumer

marked as duplicate by Community Aug 17 '18 at 10:37

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    Did answer 1's { command1 & command2; } | ... not work for you? – Michael Homer Aug 17 '18 at 10:10
  • To me it seemed it was only piping the output of command1 but never starting command2, as command1 will run indefinitely. – oh.dae.su Aug 17 '18 at 10:12
  • How did it seem that way? It doesn't do that, but that's not to say there wasn't some other issue that's your real problem. – Michael Homer Aug 17 '18 at 10:14
  • ok sorry for the wording. It only pipes the Output of command1, command2 is never started. If I reverse them, I get it the other way around. – oh.dae.su Aug 17 '18 at 10:17
  • 1
    Yeah, exactly, that's not how it works, so you do have a different problem. command1 runs in the background and command2 starts shortly after. Try { yes y & yes n ; } | cat and see. You may need to provide your actual commands for someone to help you. – Michael Homer Aug 17 '18 at 10:19
1

Remove the semicolon from your lucky guess...

Not the answer you're looking for? Browse other questions tagged or ask your own question.