2

Is it possible to do something like this in bash?

output=$(echo hello; sleep 10) &
pid=$!
# run some more commands
wait $pid
echo $output

I would like to run multiple commands in parallel, capturing their output. I'd like to do it in a "clean" way - not writing to temporary files etc.

1
  • probably try reading from the stdout files fd = 1 of the from /proc/<process_id>/fd/1 Commented Aug 25, 2011 at 18:07

1 Answer 1

3

You can use a named pipe to communicate between parent and child, see man mkfifo for details. Parent can use read command to fetch data from the pipe.

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

1 Comment

There are some subtleties to how you collect the processes too, see stackoverflow.com/a/26240420/2492.

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.