Skip to content

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

@dhanjit

Description

@dhanjit

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions