DELETED:
Just noticed this was a resurrected. I hate it when people do that! |
@GazL
You might hate that but I hate when I come to a thread via Google search results and find the resolved answer doesn't quite do it. |
oshahazard, your answer is wrong because the '-s' test checks for the existence and non-zero-byte status of a file. DISPLAY is an environmental variable which is set when X is started. Checking if DISPLAY is a non-null string (-n) is the proper check.
|
Surprised nobody got this yet.
Here's how I do it: /usr/bin/xterm -e exit > /dev/null 2>&1 [ "$?" != "0" ] && exit |
I should explain - your DISPLAY variable may set, but pointing nowhere.
If you login using putty for example, your DISPLAY gets set to something like localhost:10.0 but if you're not running a server where you came from, the DISPLAY is pointing to a non-existent server so that's why I test it anyway. |
Quote:
The only real test is to check whether there is a $DISPLAY variable set to a sane value, and then try to make an X connection to the indicated server. The X client application does that by default. One could probably contrive a special purpose application that does only that, and sets return values indicating success or its particular failure mode. The problem with using the process table to check for a running X server is of course that the X server may not be running on the same host that the application will run on, and there is the possibility the any local X server is not named 'X', and that the X server may not be accepting connections from application(s) on the local host. There is also the possibility that the running X server does not support some other required functionality, such as video modes, fonts, etc. None of these conditions are easy to detect without simply trying to make the connection and use the server. --- rod. |
Quote:
Code:
show_image() |
All times are GMT -5. The time now is 12:03 PM. |