Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

How to detect present X-Server
Hi everybody -

is there a way to make a perl program find out whether a valid X-Server
is running?
I.e. $ENV{DISPLAY} is not a dummy address, if set.

Thanks,
Matthias



Report this thread to moderator Post Follow-up to this message
Old Post
Matthias Kraatz
12-16-04 08:56 AM


Re: How to detect present X-Server
> is there a way to make a perl program find out whether a
> valid X-Server is running?
> I.e. $ENV{DISPLAY} is not a dummy address, if set.

Not in a useful way.

I have a headless (no monitor) Linux server, and a Windows
desktop with a X win server.  If I forget to run the X server it
doesn't mean that DISPLAY contains a dummy address...

If a script made a guess at whether I wanted X functionality
(say for installation), then it could get it wrong.  That would
be most annoying.

If a script wants to know if it can use the X server (or if one
exists), then it should go ahead and try.  If the toolkit returns
an error then you know you don't have one.

In the situation you want to use X if available, terminal
otherwise, wouldn't it be better just to use an option?

More detail, better answers!

Jonathan Paton

--
#!perl
$J=' 'x25 ;for (qq< 1+10 9+14 5-10 50-9 7+13 2-18 6+13
17+6 02+1 2-10 00+4 00+8 3-13 3+12 01-5 2-10 01+1 03+4
00+4 00+8 1-21 01+1 00+5 01-7 >=~/ \S\S \S\S /gx) {m/(
\d+) (.+) /x,, vec$ J,$p +=$2 ,8,= $c+= +$1} warn $J,,

Report this thread to moderator Post Follow-up to this message
Old Post
Jonathan Paton
12-16-04 01:56 PM


Re: How to detect present X-Server
Jonathan -

thanks for the input. Actually I wanted to provide more details but I
thought there would be a simple and standard solution for it (that I
hadn't found.)

Anyway, I am working on a project for interfacing  a simulation
software, creating input files, processing output, scripting variations
of parameters for huge numbers of batch simulations and all that.
For certain subprocesses (imaging, text editing, etc.) it would be
useful to know whether X functionality is there or not. Example: do I
launch vi or xedit, should I even try to display an image, start OpenDX
or not, and so on.
I thought about an option, works for me. But since a group of people is
using the tool, I want to make it as simple as possible.
What I have noticed - when started without X support - X applications
sometimes just sit there as idle processes, not quitting with an error
'cannot open display etc...'. They accumulate and waste resources.

So maybe I should change my strategy - from highest-functionality to
working-simple-but-by-default, the latter with explicit options to step up.

I thought that maybe a function/module would exist, returning true if X
supported.

Thanks for your reply and ideas,
Matthias


Jonathan Paton wrote:
 
>
>Not in a useful way.
>
>I have a headless (no monitor) Linux server, and a Windows
>desktop with a X win server.  If I forget to run the X server it
>doesn't mean that DISPLAY contains a dummy address...
>
>If a script made a guess at whether I wanted X functionality
>(say for installation), then it could get it wrong.  That would
>be most annoying.
>
>If a script wants to know if it can use the X server (or if one
>exists), then it should go ahead and try.  If the toolkit returns
>an error then you know you don't have one.
>
>In the situation you want to use X if available, terminal
>otherwise, wouldn't it be better just to use an option?
>
>More detail, better answers!
>
>Jonathan Paton
>
>
>


Report this thread to moderator Post Follow-up to this message
Old Post
Matthias Kraatz
12-16-04 08:59 PM


Re: How to detect present X-Server
> > is there a way to make a perl program find out whether a 
>
> In the situation you want to use X if available, terminal
> otherwise, wouldn't it be better just to use an option?
>

Well -- from a human-issues standpoint, requiring the user to decide
that which could be automatic is (in my arrogant opinion) the worst
solution :)

It is one of the misfeature's of emacs that always makes me grumble --
if I'm at a place where my $DISPLAY variable is set, but for one
reason or another X cannot work, it burns my cookies that I have to
remember to emacs -nw ... that it can't fall-back on its own.

The most common (and near daily for me) occurance of this is: I'm
sitting at my xterminal at home, and ssh to my colo machine (as me).
I then su to some other EUID - suddenly I have a valid DISPLAY
identifier, but that server cannot be contacted for lack of
permissions.

I'm certain that a tiny 'attempt to connect to the server on
$ENV{DISPLAY} and do nothing' program can be written.

Now, having an OPTION (in that I may safely opt out without ill
effect) that allows me to SUPPRESS that automatic check is a GOOD
thing.  But requiring me to know that my $DISPLAY is set but
unreachable is a stone in my shoe.

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Lawrence Statton - lawrenabae@abaluon.abaom s/aba/c/g
Computer  software  consists of  only  two  components: ones  and
zeros, in roughly equal proportions.   All that is required is to
sort them into the correct order.




Report this thread to moderator Post Follow-up to this message
Old Post
Lawrence Statton
12-16-04 08:59 PM


Re: How to detect present X-Server
>
> I'm certain that a tiny 'attempt to connect to the server on
$ENV{DISPLAY} and do nothing' program can be written.
>

File this under "ugly but works"

.............................. BEGIN PERL PROGRAM ......................
#!/usr/bin/perl
use strict;
use warnings;
my $message = `xlsfonts -fn NOTBLOODLYLIKELYTOOCCUR 2>&1 `;
unless ( $message =~ /pattern.*unmatched/ ) {
print "No X for you!" ;
} else {
print "It's not called X-Windows.  It is a window system called `X'\n";
}
............................... END PERL PROGRAM .......................

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Lawrence Statton - lawrenabae@abaluon.abaom s/aba/c/g
Computer  software  consists of  only  two  components: ones  and
zeros, in roughly equal proportions.   All that is required is to
sort them into the correct order.

Report this thread to moderator Post Follow-up to this message
Old Post
Lawrence Statton
12-16-04 08:59 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:37 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.