您的位置:首页 > 运维架构 > Linux

How do I set the DISPLAY variable on Linux

2012-07-17 22:11 323 查看
startx

ps -e | grep X

pidof X && echo "yup X server is running"



if you're on the main display, then
export DISPLAY=:0.0


or if you're using csh or tcsh
setenv DISPLAY :0.0


Actually, I'm surprised it isn't set automatically. Are you trying to start this application from a non-graphic terminal? If not, have you modified the default .profile, .login, .bashrc or .cshrc?

Note that setting the DISPLAY to :0.0 pre-supposes that you're sitting at the main display, as I said, or at least that the main display is logged on to your user id. If it's not logged on, or it's a different userid, this will fail.

If you're coming in from another machine, and you're at the main display of that machine and it's running X, then you can use "ssh -X hostname" to connect to that host, and ssh will forward the X display back. ssh will also make sure that the DISPLAY environment
variable is set correctly (providing it isn't being messed with in the various dot files I mentioned above). In a "ssh -X" session, the DISPLAY environment variable will have a value like "localhost:11.0", which will point to the socket that ssh is tunnelling
to your local box.

f you're already within a graphical environment, try export DISPLAY=:0 for bash like shells (bash, sh, etc) or setenv DISPLAY :0 for C shell based shells (csh, tcsh, etc)

If you've connected from another machine via SSH, you use the -X option to display the graphical interface on the machine you're sitting at (provided there's an X server running there (such as xming for windows, and your standard Linux X server).
Don't forget to execute "host +" on your "home" display machine, and when you ssh to the machine you're doing "ssh -x hostname"

Using Linux, and especially configuring Linux, normally require some insight, and we strongly suggest (to inexperienced linux users) to get some help from a system administrator.

In short, you must open up a shell (csh, bash, etc), so that it is possible to issue commands on Linux. Then you must enter the commands to set the environment variable, as explained in the setup-instructions.

Also, if you are starting Tomcat (or other application server) automatically by calling the startup-script in the this script:

/etc/rc.local

..then you must make sure that the command for setting the DISPLAY variable is called before starting the application server.

There are many discussions/guides on the Internet regarding this issue. Here is an extract from one:

"1. A Little Theory

The magic word is DISPLAY. In the X window system, a display consists

(simplified) of a keyboard, a mouse and a screen. A display is managed

by a server program, known as an X server. The server serves

displaying capabilities to other programs that connect to it.

A display is indicated with a name, for instance:

* DISPLAY=light.uni.verse:0

* DISPLAY=localhost:4

* DISPLAY=:0

The display consists of a hostname (such as light.uni.verse and

localhost), a colon (:), and a sequence number (such as 0 and 4). The

hostname of the display is the name of the computer where the X server

runs. An omitted hostname means the local host. The sequence number is

usually 0 -- it can be varied if there are multiple displays connected

to one computer.

If you ever come across a display indication with an extra .n attached

to it, that's the screen number. A display can actually have multiple

screens. Usually there's only one screen though, with number n=0.

Other forms of DISPLAY exist, but this will do for our purposes.

2. Telling the Client

The client program (for instance, your graphics application) knows

which display to connect to by inspecting the DISPLAY environment

variable. This setting can be overridden, though, by giving the client

the command line argument -display hostname:0 when it's started. Some

examples may clarify things.

Our computer is known to the outside as light, and we're in domain

uni.verse. If we're running a normal X server, the display is known as

light.uni.verse:0. We want to run the drawing program xfig on a remote

computer, called dark.matt.er, and display its output here on light.

If you have csh running on the remote computer:

dark% setenv DISPLAY light.uni.verse:0

dark% xfig &

Or alternatively:

dark% xfig -display light.uni.verse:0 &

If you have sh running on the remote computer:

dark$ DISPLAY=light.uni.verse:0

dark$ export DISPLAY

dark$ xfig &

Or alternatively:

dark$ DISPLAY=light.uni.verse:0 xfig &

Or, of course, also:

dark$ xfig -display light.uni.verse:0 &

It seems that some versions of telnet automatically transport the

DISPLAY variable to the remote host. If you have one of those, you're

lucky, and it's automatic. If not, most versions of telnet _do_

transport the TERM environment variable; with some judicious hacking

it is possible to piggyback the DISPLAY variable on to the TERM

variable."
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐