neno: Rewrite: easier to understand the redirection.

This commit is contained in:
Ole Tange 2020-06-03 17:44:04 +02:00
parent 38dfa767fb
commit 1230591ae5

View file

@ -34,7 +34,7 @@ No output if file exists:
=head1 AUTHOR =head1 AUTHOR
Copyright (C) 2017 Ole Tange, Copyright (C) 2017-2020 Ole Tange,
http://ole.tange.dk and Free Software Foundation, Inc. http://ole.tange.dk and Free Software Foundation, Inc.
@ -64,23 +64,21 @@ B<man>
=cut =cut
_tmp=$(mktemp -d /tmp/no-error.XXXXX) _tmp=$(mktemp -d /tmp/no-error.XXXXX)
true 2>$_tmp/stderr >$_tmp/stdout true >$_tmp/stdout 2>$_tmp/stderr
# Save original stdout/stderr # Open the tmp-files for reading on file descriptor 21+22
exec 11>&1 12>&2
# Redirect stdout/stderr to tmpfiles
exec 1>$_tmp/stdout 2>$_tmp/stderr
# Open the tmpfiles for reading
exec 21<$_tmp/stdout 22<$_tmp/stderr exec 21<$_tmp/stdout 22<$_tmp/stderr
# Unlink files (but keep them open) (
rm -rf $_tmp # Unlink tmp-files (but keep them open)
rm -rf $_tmp
eval "$@" eval "$@"
) >$_tmp/stdout 2>$_tmp/stderr
_error=$? _error=$?
if [ $_error == 0 ] ; then if [ $_error == 0 ] ; then
# skip # skip
true true
else else
cat 0<&21 >&11 cat 0<&21
cat 0<&22 >&12 cat 0<&22 >&2
fi fi
exit $_error exit $_error