简体   繁体   中英

Undo global STDERR -> STDOUT redirection

I'm working on a script that ssh's into hosts and then sudo's to a privileged user. Since our hosts do not allow sudo with non-tty sessions, pseudo-tty is enabled.

pseudo-tty automatically redirects all STDERR output to STDOUT. This is causing a litany of issues for the project, as dependent libraries do not handle STDERR output well.

Is it possible to undo the STDERR -> STDOUT output redirect? In other words, is it possible to globally mandate that all STDERR output not be sent to STDOUT? I know it's possible to do on a per-command basis, but I'm looking for a way to do this that only has to be done once - ideally when ssh'ing to the host.

You can't "undo" a redirection, but you can redirect somewhere else.

A "bare" redirection in a shell script (eg, 2>/dev/null ) on a line by itself will redirect stdout or stderr for the shell itself and so for all future commands the shell runs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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