简体   繁体   English

重击最后的多个管道和背景,获取第一个的状态代码

[英]Bash multiple pipes and background in last, get status code of the first one

I am having following code 我有以下代码

process_file $2 $3 | prefix "[JIDDD: $3]" |& logger &

And what I would need to have is return/exitcode of the process_file function, how can I have that? 我需要的是process_file函数的返回/退出代码,我该怎么办呢?

Already tried PIPESTATUS and variables, but as the process moved to background we don't have access anymore. 已经尝试过PIPESTATUS和变量,但是随着过程移至后台,我们不再具有访问权限。

You can have the background process write the status to a file. 您可以让后台进程将状态写入文件。

(process_file $2 $3 | prefix "[JIDDD: $3]" |& logger; echo ${PIPESTATUS[0]} > /tmp/process_file.$$) &
wait
status=$(</tmp/process_file.$$)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM