in reply to Re^2: How to detect X?
in thread How to detect X?

 eval really isn't reliable here. The program may very well start in X if X is running, even if it is not called under X.
 IMHO, you really should check for $ENV{DISPLAY}, if X is running and DISPLAY is not set it is really the user's problem, not yours.
 Some gui toolkits have their own internal checks for this stuff, gtk has something like init_check() (wondering if it can run or not) maybe you could find something similar in Tk. This seems too low-level though for whatever the gui toolkit not to have.
 But again, until then, use $ENV{DISPLAY}. If the user doesn't have it set and has X running, i can bet it wouldn't be just your application he would have problems with.

--
perl -MLWP::Simple -e'print$_%%\n|,<br> get(q=http://cpan.org/misc/japh=)))'

Replies are listed 'Best First'.
Re^4: How to detect X?
by Anonymous Monk on Feb 21, 2005 at 14:22 UTC
    $ENV{DISPLAY} not being set if X is running is only one part of the problem - and the less problematic one, because in that case, it runs the command line version. The other problem is $ENV{DISPLAY} being set and X not running. Then it will try to launch an X application.
      So can you not check for BOTH a non-empty DISPLAY *and* check the process table (via ps or whatever is handy) for the X process?
        In general, no. Because in general, the X server (which DISPLAY is pointing at) may not even be running on the local machine. You'd have to have some way of checking for a running X server process on some other machine on the network, which itself is in general a "hard" problem. You'd do better just to check if you can make an X connection directly to the specified X server.