开发者

Capturing output of asynchronous bash commands?

开发者 https://www.devze.com 2023-03-30 15:09 出处:网络
Is it possible t开发者_如何学Co do something like this in bash? output=$(echo hello; sleep 10) &

Is it possible t开发者_如何学Co 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消