On 28 February 2010 01:27, Vincent Carmona
> Other applications do not seem to write on ~/.xsession-errors.
The point is that the other applications aren't writing to STDOUT.
That's why you don't see output. I've written a lot about why
you don't want to do what you think you want to do. But
it's possible you would rather not read that. If so, I've written
a solution that should work and not break other people's
expectation of your app. You can skip down to see it.
I'm not sure that you're understanding how it works. Every application
has a default file handle for STDOUT and STDERR. Where these
are sent is not (and should not) be determined by the application.
It is up to the user to determine where those should go. Redirecting
STDOUT or STDERR breaks your application. The one exception
is when you definitely don't want to write to one of the file handles
(for example a daemon) in which case you should close the file
handle (this allows the shell to detach more easily).
When you run an application, STDOUT and STDERR are attached
to your TTY (or PTS in the case of an xterm, etc) by default, but
you can redirect the output anywhere you want (in bash you use
the > or 2> redirectors). This is important in case the user wants
to parse output that you have. You can not know how the user
will launch the application or what they want to do with the output.
Deciding for them reduces their ability to use your application
integrated with their own solution. That's why I said it's broken.
The problem you are running into is that the X server is (by default)
running on TTY7. So output from the X server will go to TTY7.
But you can't really see TTY7 because you have an X display there.
GDM (the Gnome Display Manager) will redirect the output to a file
so you can see it. Now because I haven't looked at it I don't know
who exactly is redirecting STDOUT to .xsession-errors -- but it's
probably GDM. GDM then starts the X server and a whole host
of other stuff including your window manager, gnome-session,
gnome-panel, etc, etc. But each of these processes inherits its
STDOUT from it's parent (for the sake of argument, we'll call it
GDM, but I haven't looked at the exact startup mechanism of
GNOME). Since STDOUT is redirected to .xsession-errors in
the parent process, it is in each of the child processes too.
So when you run an application "from the GUI" STDOUT is
set up as .xsession-errors -- for all applications.
When you run gnome-terminal (or xterm or whatever) it creates
a new PTS (sort of like a pseudo TTY) and sets STDOUT to
that PTS. That's why applications run from a terminal window
have their output printed there. You definitely do not what to
change that behaviour from your application. It breaks what
normal people think your app should be doing.
SKIP TO HERE FOR THE SOLUTION
It is quite possible that you have debug information
or whatever that you don't want to output when the application
is normally launched. The most common way to do this is
simply to have a flag (say, "-debug") that turns on printing
of the information. That way when someone types
"theAPP -debug" they get the information and when the type
"theAPP" they get nothing.
Sometimes you don't want to (or can't) do that for some reason.
In this case you can simply redirect STDIO or STERR when the
application is invoked from the GUI. In GNOME the menus, etc,
are populated by .desktop files.
If you look in /usr/share/applications and /usr/share/app-install/desktop
you can see these files. Make one for your application and in
the Exec line redirect the output to /dev/null. Honestly I don't know
much about these things. But this would be the best place to redirect
Hope that helps,