Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
No such thing as a small change
 
PerlMonks  

Re: How to detect X?

by zentara (Cardinal)
on Feb 21, 2005 at 07:41 UTC ( [id://433033]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to How to detect X?

How about a plain old eval?
#!/usr/bin/perl use warnings; use strict; use Tk; my $mw; my $xtest = eval( 'my $mw = new MainWindow;' ); if($@) { chomp($@); print "X error: '$@'\n"; } else { print "X ok\n"; } MainLoop;

I'm not really a human, but I play one on earth. flash japh

Replies are listed 'Best First'.
Re^2: How to detect X?
by blazar (Canon) on Feb 21, 2005 at 07:55 UTC
    How about a plain old eval?
    Indeed: 432984!
       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=)))'

        $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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://433033]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.