2

Is there an easy way to run a command from the terminal the same way it is run from GNOME's Alt + F2, redirecting stdout and stderr to systemd's journal?

I've tried gmrun (does not redirect outputs), gtk-launch (works only for .desktop files in /usr/share/applications).

Is there a GNOME or a systemd command to do this?

terdon
  • 242,166

2 Answers2

3

I think that you should use the logger(1) utility, which works no matter if your system is using systemd or rsyslogd.

your_prog 2>&1 | logger -t your_prog

On systems with systemd, there's also systemd-cat which is specifically using systemd's "streaming" logging api (sd_journal_stream_fd(3), /run/systemd/journal/stdout) instead of the standard syslog(3):

your_prog 2>&1 | systemd-cat -t your_prog

systemd-cat -t your_prog your_prog

To save another search: If you want to pipe only the stderr but not the stdout, you can use

log_stderr(){ { "$@" 2>&1 >&3 3>&- | logger -t "$1"; } 3>&1; }
log_stderr your_prog
1

systemd-run --user ...

Unfortunately, the most user-friendly mode is not used by default.

By default, services created with systemd-run default to the simple type [...] Consider using the exec service type (i.e. --property=Type=exec) to ensure that systemd-run returns successfully only if the specified command line has been successfully started.

This more useful setting was added later. Personally, I do not think I would remember this detail. So I would prefer to use a short wrapper script.

sourcejedi
  • 50,249