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