How do I set the DISPLAY variable on Linux

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


Here is a possible implementation of the book class and the main program: ```python class Book: def __init__(self, title, author, year, is_available): self.title = title self.author = author self.year = year self.is_available = is_available def load_data(self): self.title = input("Enter book title: ") self.author = input("Enter book author: ") self.year = int(input("Enter year of publication: ")) self.is_available = True def display_data(self): print(f"Title: {self.title}") print(f"Author: {self.author}") print(f"Year of publication: {self.year}") print(f"Availability: {'in the library' if self.is_available else 'taken out'}") def is_in_library(self): return self.is_available # main program book1 = Book("The Catcher in the Rye", "J.D. Salinger", 1951, True) book2 = Book("To Kill a Mockingbird", "Harper Lee", 1960, False) book1.display_data() print(book1.is_in_library()) book2.load_data() book2.display_data() print(book2.is_in_library()) ``` In this program, we define a Book class with four attributes: title, author, year, and is_available. The constructor initializes these attributes with the values passed as arguments. The load_data() method prompts the user to enter the data for a book, and sets the corresponding attributes of the book object. The display_data() method prints the data for a book to the console. The is_in_library() method returns True if the book is in the library, False otherwise. In the main program, we create two Book objects, book1 and book2, with different initial values for their attributes. We call the display_data() and is_in_library() methods to test the functionality of the class. We also call the load_data() method for book2 to demonstrate how it can be used to set the attributes of a book object.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值