[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-bash] coproc handling stderr

From: João Eiras
Subject: [Help-bash] coproc handling stderr
Date: Sun, 1 Jan 2017 18:14:00 +0100


I'm coding a script that at some point I need to take over all the
output from a call, both stdout and stderr.

So far I'm doing this (mostly)

function run_background_command {
  trap '{ quit=1 ; }' SIGUSR1
  while [[ ! "$quit" ]]; do
    read -r -t 0.1 -u 101 line_stdout || read -r -t 0.1 -u 102 line_stderr
    # blah blah blah
local p1="/tmp/$BASHPID.p1" p2="/tmp/$BASHPID.p2"
mkfifo -m 0600 "$p1" "$p2"
handle_output 101<"$p1" 102<"$p2" &
local output_task=$
"address@hidden" 1>"$p1" 2>"$p2"
kill -s SIGUSR1 "$output_task"

The main to remark here are the two pipes and how they are used.

Meanwhile I found out about bash coproc [1] feature, which would save
some of the boilerplate code and I would not need to create two named
pipes, which is desirable since I would have less cleanup to do and
for the theoretical case where my script is running in a readonly

Unfortunately, the coproc feature only pipes stdin and stdout, not
stderr (I've confirmed that by looking at the bash source code [2]),
unless I merge both stdout and stderr, which I don't want to do.

So, the question is, coproc with stderr... how ? Worthy of a feature request ?


[2] git://

reply via email to

[Prev in Thread] Current Thread [Next in Thread]