crigler / dtach

A simple program that emulates the detach feature of screen
GNU General Public License v2.0
476 stars 50 forks source link

Redirect stdout/stderr of the executed command when running as foreground #16

Open dhanjit opened 5 years ago

dhanjit commented 5 years ago

dtach -N /tmp/d1 echo "ASD" exits silently.

Let me explain an example where this is definitely a requirement. Consider the systemd unit as below:

[Unit]
Description=systemd integration for rtorrent using dtach - starts/stops rtorrent instances on startup/shutdown
Wants=network-online.target
After=network-online.target

[Service]
Environment="TERM=rxvt-unicode-256color"
KillMode=none
ExecStartPre=/usr/bin/mkdir -p %t/dtach
ExecStart=/usr/bin/dtach -N %t/dtach/rtorrent /usr/bin/rtorrent -n -o import=%E/rtorrent/.rtorrent.rc
ExecStop=/usr/bin/killall -u %u -w -s INT /usr/bin/rtorrent
# Refer https://github.com/crigler/dtach/issues/12, Success is error code 1
SuccessExitStatus=1

[Install]
WantedBy=default.target

Now what happens when rtorrent fails to start, say to due a config error? It prints to stderr/stdout. So will almost every cli program ranging from a simple echo to something heavy like rtorrent.

If I am running in foreground, then it would be prudent to redirect stdout/stderr of the command in question, or atleast have an option to do so.