On Sat, Feb 27, 2010 at 4:27 PM, Vincent Carmona <email@example.com> wrote:
Thanks for you reply.
You have confirm my doubts that "gnome" redirect the standard output.
Users of my application complain about ~/.xsession-errors being filled
with my application outputs.
Other applications do not seem to write on ~/.xsession-errors.
Actually, any application launched that is parented by your window manager that prints to stdout/stderr would typically write to ~/.xsession-errors. It's quite common. This happens in many setups, not just GNOME (for instance, I use openbox as my window manager, and I get plenty of stuff in my ~/.xsession-errors.
The behaviour I would implement is:
- if launched "graphically", set $stdout and $stderr to /dev/null,
- if launched by terminal app, keep $stdout and $stderr.
Can I do that ?
Yes that is possible. In Ruby, there is IO::reopen, and can be used on $stdout and $stderr. You could open a log file, then call $stdout.reopen(your_log_file_io). I'm not sure how to detect if you were launched from a terminal though. I'm thinking of a complicated process involving checking parent pids, but there's probably an easier way.