Set Environment Variable DISPLAY

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tanyali
    New Member
    • Feb 2007
    • 43

    Set Environment Variable DISPLAY

    How to set up the environment variable DISPLAY in Linux :
    1- Redhat
    2- SuSe

    I used : export DISPLAY=donner: 0.0 donner is the domain name.

    it said :
    you must specify the environment variable DISPLAY
    e.g. setenv DISPLAY aran:0.0
    or setenv DISPLAY fl1:0.0
    ... etc
    Program terminating
    DISPLAY=

    Who knows, please Help !
    Thank you very much.
    Tanya
  • prn
    Recognized Expert Contributor
    • Apr 2007
    • 254

    #2
    I am going to assume you meant that donner is the hostname, not the domain name. The display must point to an individual computer, not a domain.

    When you say "it said" what is "it"? The graphical program you were attempting to run? How and when did you start that program?

    If you "export DISPLAY=donner: 0.0" in a terminal window, the environmental variable DISPLAY is set ONLY within that specific process and others started from it. The command above exports the variable DISPLAY to itself and its "children" processes. If you set DISPLAY that way and then try to start, e.g., the GIMP from a menu or a desktop icon, then the gimp is not running within that same shell instance so it does not inherit DISPLAY from the process where you set it. Instead, you might try:
    Code:
    export DISPLAY=donner:0.0
    gimp &
    In that case the GIMP will inherit DISPLAY from the process where you set it.

    That's my best guess about what happened based on what you have said so far. If it's wrong, I won't be surprised. Come on back and tell us.

    Best Regards,
    Paul

    Comment

    • tanyali
      New Member
      • Feb 2007
      • 43

      #3
      Originally posted by prn
      I am going to assume you meant that donner is the hostname, not the domain name. The display must point to an individual computer, not a domain.

      When you say "it said" what is "it"? The graphical program you were attempting to run? How and when did you start that program?

      If you "export DISPLAY=donner: 0.0" in a terminal window, the environmental variable DISPLAY is set ONLY within that specific process and others started from it. The command above exports the variable DISPLAY to itself and its "children" processes. If you set DISPLAY that way and then try to start, e.g., the GIMP from a menu or a desktop icon, then the gimp is not running within that same shell instance so it does not inherit DISPLAY from the process where you set it. Instead, you might try:
      Code:
      export DISPLAY=donner:0.0
      gimp &
      In that case the GIMP will inherit DISPLAY from the process where you set it.

      That's my best guess about what happened based on what you have said so far. If it's wrong, I won't be surprised. Come on back and tell us.

      Best Regards,
      Paul
      Yes, donner is the hostname, not domain name.
      The graphical program I am attempting to run is named " xgrbplt " by using :
      xgrbplt GRIB_file_name
      if success, it will display a graph,
      but now it returns : unable to open display "donner:0.0

      another thing is after I use " export DISPLAY=donner: 0.0 " and "gimp &"
      then type "display" normally , a picture will display, but it returns : GIMP could not initialise the graphical user interface.
      Make sure a proper setup for your display environment exists.

      display: unable to open X server `donner:0.0'.
      [1]+ Exit 1 gimp

      what do you think of this ?
      Thanks, waiting for your reply.
      Tanya

      Comment

      • prn
        Recognized Expert Contributor
        • Apr 2007
        • 254

        #4
        That's odd. That's what I think.

        But then X is often odd.

        So let's try to go back to basics and see what we know:

        1) Is donner running RedHat (version?) or is it Suse?

        2) Are you logged in to a graphical interface? That is, is your terminal a window on your screen or is it the whole screen?

        3) If you log out and log in fresh, what does the command "env" show? If you are using a graphical UI, then it ought to have a DISPLAY set already.

        4) Are you sitting in front of donner's console or are you actually at a different computer and connected to donner by SSH or something? Or is it that you are at donner and trying to run the graphical program on some other computer but with the display set to donner?

        Let us know the answers to these questions and either we can come up with something helpful or at least maybe we'll know more and better questions to ask. :)

        Paul

        Comment

        • Motoma
          Recognized Expert Specialist
          • Jan 2007
          • 3236

          #5
          Originally posted by tanyali
          Yes, donner is the hostname, not domain name.
          The graphical program I am attempting to run is named " xgrbplt " by using :
          xgrbplt GRIB_file_name
          if success, it will display a graph,
          but now it returns : unable to open display "donner:0.0

          another thing is after I use " export DISPLAY=donner: 0.0 " and "gimp &"
          then type "display" normally , a picture will display, but it returns : GIMP could not initialise the graphical user interface.
          Make sure a proper setup for your display environment exists.

          display: unable to open X server `donner:0.0'.
          [1]+ Exit 1 gimp

          what do you think of this ?
          Thanks, waiting for your reply.
          Tanya

          Silly question, but have you added your machine using xhost? Does xclock work?

          Comment

          • tanyali
            New Member
            • Feb 2007
            • 43

            #6
            Originally posted by prn
            That's odd. That's what I think.

            But then X is often odd.

            So let's try to go back to basics and see what we know:

            1) Is donner running RedHat (version?) or is it Suse?

            2) Are you logged in to a graphical interface? That is, is your terminal a window on your screen or is it the whole screen?

            3) If you log out and log in fresh, what does the command "env" show? If you are using a graphical UI, then it ought to have a DISPLAY set already.

            4) Are you sitting in front of donner's console or are you actually at a different computer and connected to donner by SSH or something? Or is it that you are at donner and trying to run the graphical program on some other computer but with the display set to donner?

            Let us know the answers to these questions and either we can come up with something helpful or at least maybe we'll know more and better questions to ask. :)

            Paul
            1) donner is running on SuSe and the computer(versio n: RedHat)'s hostname is roadedit.

            2) I am using roadedit logged into Suse as a root , and my terminal is a window on my screen , not the whole screen.

            3)the command "env" shows :
            LESSKEY=/etc/lesskey.bin
            MANPATH=/opt/intel/idbe/9.1.036/man:/opt/intel/fc/9.1.036/man:/usr/local/man:/usr/share/man:/usr/X11R6/man:/opt/gnome/share/man
            INFODIR=/usr/local/info:/usr/share/info:/usr/info
            NNTPSERVER=news
            HOSTNAME=donner
            XKEYSYMDB=/usr/X11R6/lib/X11/XKeysymDB
            GNOME2_PATH=/usr/local:/opt/gnome:/usr
            INTEL_LICENSE_F ILE=/opt/intel/fc/9.1.036/licenses:/opt/intel/licenses:/home/tli/intel/licenses
            TERM=xterm
            SHELL=/bin/bash
            HOST=donner
            HISTSIZE=1000
            PROFILEREAD=tru e
            EMOSLIBOLD=-L/usr/local/lib_intel -lemosold
            BUFR_TABLES=/usr/local/bufr_intel
            MORE=-sl
            QTDIR=/usr/lib/qt3
            USER=tli
            JRE_HOME=/usr/lib/jvm/jre
            GROFF_NO_SGR=ye s
            HISTFILESIZE=10 00
            http_proxy=http ://192.122.223.140 :80
            LIBGL_DRIVERS_P ATH=/usr/X11R6/lib/modules/dri
            LS_COLORS=no=00 :fi=00:di=01;34 :ln=00;36:pi=40 ;33:so=01;35:do =01;35:bd=40;33 ;01:cd=40;33;01 :or=41;33;01:ex =00;32:*.cmd=00 ;32:*.exe=01;32 :*.com=01;32:*. bat=01;32:*.btm =01;32:*.dll=01 ;32:*.tar=00;31 :*.tbz=00;31:*. tgz=00;31:*.rpm =00;31:*.deb=00 ;31:*.arj=00;31 :*.taz=00;31:*. lzh=00;31:*.zip =00;31:*.zoo=00 ;31:*.z=00;31:* .Z=00;31:*.gz=0 0;31:*.bz2=00;3 1:*.tb2=00;31:* .tz2=00;31:*.tb z2=00;31:*.avi= 01;35:*.bmp=01; 35:*.fli=01;35: *.gif=01;35:*.j pg=01;35:*.jpeg =01;35:*.mng=01 ;35:*.mov=01;35 :*.mpg=01;35:*. pcx=01;35:*.pbm =01;35:*.pgm=01 ;35:*.png=01;35 :*.ppm=01;35:*. tga=01;35:*.tif =01;35:*.xbm=01 ;35:*.xpm=01;35 :*.dl=01;35:*.g l=01;35:*.wmv=0 1;35:*.aiff=00; 32:*.au=00;32:* .mid=00;32:*.mp 3=00;32:*.ogg=0 0;32:*.voc=00;3 2:*.wav=00;32:
            XNLSPATH=/usr/X11R6/lib/X11/nls
            METVIEW_DIR=/usr/local/apps/Metview
            ENV=/etc/bash.bashrc
            HOSTTYPE=i386
            MOZ_PRINTER_NAM E=pcol1
            FROM_HEADER=
            PAGER=less
            CSHEDIT=emacs
            XDG_CONFIG_DIRS =/usr/local/etc/xdg/:/etc/xdg/:/etc/opt/gnome/xdg/
            MINICOM=-c on
            PATH=/opt/intel/idbe/9.1.036/bin:/opt/intel/fc/9.1.036/bin:/home/tli/bin:/usr/local/bin:/usr/bin:/sbin:/usr/X11R6/bin:/usr/sbin:/bin:/usr/games:/opt/gnome/bin:/opt/kde3/bin:/usr/lib/jvm/jre/bin:/usr/lib/mit/bin:/usr/lib/mit/sbin:/usr/lib/qt3/bin
            MAIL=/var/mail/tli
            CPU=i686
            JAVA_BINDIR=/usr/lib/jvm/jre/bin
            BUFRTAB_DIR=/usr/local/bufr_intel
            PWD=/home/tli
            INPUTRC=/home/tli/.inputrc
            JAVA_HOME=/usr/lib/jvm/jre
            MAGLIB=-L/usr/local/lib/magics/lib -lmagics -lMvDevices -L/usr/local/lib/magics/lib -lmagics -L/usr/lib -lGLw -lGLU -lGL -L/usr/lib -L/usr/X11R6/lib -lgd -lpng
            -lz -ljpeg -lfreetype -L/usr/X11R6/lib -L/usr/lib -lXm -lXt -lXmu -lXi -lXext -lX11 -lXp -lm -L/usr/lib -lstdc++ -lm
            EDITOR=/bin/vi
            LANG=en_GB.UTF-8
            PYTHONSTARTUP=/etc/pythonstart
            TEXINPUTS=:/home/tli/.TeX:/usr/share/doc/.TeX:/usr/doc/.TeX
            HOME=/root
            SHLVL=2
            EMOSLIB=-L/usr/local/lib_intel -lemos
            MAG_HOME=/usr/local/lib/magics
            OSTYPE=linux
            LESS_ADVANCED_P REPROCESSOR=no
            XCURSOR_THEME=I ndustrial
            LS_OPTIONS=-A -N --color=tty -T 0
            WINDOWMANAGER=/usr/X11R6/bin/gnome
            GTK_PATH=/usr/local/lib/gtk-2.0:/opt/gnome/lib/gtk-2.0:/usr/lib/gtk-2.0
            F_UFMTENDIAN=bi g
            LOGNAME=tli
            MACHTYPE=i686-suse-linux
            LESS=-M -I
            G_FILENAME_ENCO DING=@locale,UT F-8,ISO-8859-15,CP1252
            CVS_RSH=ssh
            ACLOCAL_FLAGS=-I /opt/gnome/share/aclocal
            XDG_DATA_DIRS=/usr/local/share/:/usr/share/:/etc/opt/kde3/share/:/opt/kde3/share/:/opt/gnome/share/
            LESSOPEN=lessop en.sh %s
            PKG_CONFIG_PATH =/usr/local/lib/pkgconfig:/usr/local/share/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig:/opt/kde3/lib/pkgconfig:/opt/gnome/lib/pkgconfig:/opt/gnome/lib/pkgconfig:/opt/gnome/share/pkgconfig
            ARCH=LINUX
            INFOPATH=/usr/local/info:/usr/share/info:/usr/info:/opt/gnome/share/info
            LESSCLOSE=lessc lose.sh %s %s
            G_BROKEN_FILENA MES=1
            COLORTERM=1
            JAVA_ROOT=/usr/lib/jvm/jre
            mc=() { . /usr/share/mc/bin/mc-wrapper.sh
            }
            _=/usr/bin/env

            4) I am using my computer named roadedit(Redhat ) logged into donner(Suse) as a root to use this command "xgrbplt" which returns a graph in a window on my screen.

            and the question is ( this is actually what I want to do ! ) :
            donner is the server, I want to use this page( using Firefox ) either on my computer or donner itself .
            http://donner.aaa..../~lmcelwain/xgrbplt.php in this page
            I embedded shell command in php :
            the code is :
            /*
            <?php
            $name = $_POST['gname'] ;
            chdir("/home/lmcelwain...... ");
            echo $name ;
            $cmd="xgrbplt $name";
            $output=shell_e xec($cmd);
            echo "<pre>$outp ut</pre>";
            ?>
            */

            I have used this way with other shell command , and it worked.
            but here, result is :
            -----------
            SCRATCH=/18475
            Running xgrbplt.x
            You must specify the environment variable DISPLAY
            e.g. setenv DISPLAY aran:0.0
            or setenv DISPLAY fl1:0.0
            ... etc
            Program terminating
            DISPLAY=
            ------------
            I got the same result from that page( http://donner......) either on donner or my computer.

            result expected from this page should be a graph displayed in a window in a terminal or a web page, I am not sure, bcs I never get it work.

            Paul, Thanks for you attention !
            Tanya

            Comment

            • tanyali
              New Member
              • Feb 2007
              • 43

              #7
              Originally posted by Motoma
              Silly question, but have you added your machine using xhost? Does xclock work?
              xclock works on my computer , hostnam: roadedit, RedHat
              xclock does work on donner.
              xhost works on neither.

              Comment

              • prn
                Recognized Expert Contributor
                • Apr 2007
                • 254

                #8
                Hi Tanya,

                I think I'm starting to get a little better picture of what you're doing, but to the extent that I understand that, I think I see a number of problems.

                First, stop running as root. Overall, that's a really bad idea. The root account needs to be used for various admin tasks, but you should have a "normal" user account (on both machines) for user-level tasks. For what you are doing here, you really don't want to be root. For web surfing, or generating graphics of whatever sort, log in as a normal user. One of the big problems with most MS windows systems has always been that users have needed admin privs for trivial tasks that should not have admin privs. A result of that has been that there are too many ways to seriously mess up the whole system. With Vista, MS has moved toward requiring a better separation of privs and that is all to the good. Unix/Linux have always had a pretty good separation of privs (some OSs are even better about that, but that's a whole nother discussion). Learn to run as a user and you will definitely save yourself problems in the future.

                Second, it looks like your connection from roadedit to donner is probably by telnet or rsh. Switch to using SSH. You won't regret that either. It's much more secure.

                Third, since you are using roadedit as your screen, that's where you want the results of the graphing displayed. If DISPLAY is on donner:0.0 (i.e., the console), you will never see the results, since you are not looking at donner's console. Before you do anything more run the command:
                echo $DISPLAY
                on roadedit. You will probably see something like:
                :0.0
                This indicates that your DISPLAY envirionmental variable is properly set on roadedit, where you actually are. You could set DISPLAY on donner to point to roadedit:0.0 too, but there is a better way.

                If you take recommendation #2 above and use SSH to connect from roadedit to donner, then you can set it to handle DISPLAY automatically:
                Edit /etc/ssh/sshd_config on donner. You should find the line containing "X11Forwarding" . It may say:
                #X11Forwarding no
                It needs to say:
                X11Forwarding yes

                On RedHat systems, if you changed /etc/ssh/sshd_config you will need to use the command:
                /etc/init.d/sshd restart
                I suspect SUSE will be similar, but I'm not positive about how the init scripts are set up on SUSE. They may be in a slightly different location.

                Once sshd is correct on donner, you should now connect from roadedit to donner using a command like:
                ssh -Y tanya@donner
                (Note that the Y is capitalized.) Now, on donner when you say:
                echo $DISPLAY
                you should see somthing like:
                localhost:10.0

                If you try
                xclock &
                on donner, your xclock should appear on roadedit's screen because your display is now "tunneled" through your ssh connection back to roadedit.

                If that all worked, you should now be able to run xgrbplt on donner directly from the command line and the result will show up on roadedit's screen.

                I'm less confident that you can run xgrbplt by means of a script in a web page and have the result show up in your browser window on roadedit. The script you have strikes me as pretty unlikely to work regardless of your environment variables. That sort of script works great for text, but I don't think you can do that for arbitrary graphics. If xgrbplt can output graphics in a file format that browsers understand, e.g., png or jpeg, then the script might be adapted, but it certainly won't work for just any graphics that your X11 display knows how to render. Googling for "xgrbplt" produced no hits, so I don't have any clue at all about its capabilities.

                So if you just want the graphs for yourself, then you can see them using ssh, but if you are trying to make them available to a larger audience using a web browser, then you are going to need to make xgrbplt (or some other program) produce suitable intermediate files that you can put into a web page. I don't think setting DISPLAY is going to help you there. (And I don't know if xgrbplt is capable of producing png, jpeg or similar files anyway.) For this to work, you would need to have a way to turn off xgrbplt's requirement for DISPLAY and make its output go to a suitable file in a location where you can put an IMG tag in your generated HTML.

                HTH,
                Paul

                Comment

                • Spork Schivago
                  New Member
                  • Dec 2016
                  • 1

                  #9
                  I'm sorry to dig up an old thread here but I came here looking for answers. I had the same problem, I couldn't start any GUIs from a terminal. I'm running OpenSuSE. I did manage to find the problem though.

                  If I start a regular terminal window and run su to switch to root, I can simply run:
                  Code:
                  export DISPLAY=:1
                  Where :1 is my X-Windows display.

                  However, if I start the terminal window with something like this:
                  Code:
                  /usr/bin/gnome-terminal -e pkexec
                  So it starts a root terminal instead of a normal user terminal window, setting the DISPLAY variable is not enough.

                  On my system, I had to run these two commands to properly be able to start a GUI program, as root, from a terminal window.
                  Code:
                  export DISPLAY=:1
                  export XAUTHORITY=/run/user/1000/gdm/Xauthority
                  If the .xauth* file exists under the /root directory, then just set XAUTHORITY to that.

                  For example:
                  Code:
                  eugene:/home/spork # ls /root/.xauthMPjGOB
                  /root/.xauthMPjGOB
                  
                  eugene:/home/spork # export DISPLAY=:1
                  eugene:/home/spork # export XAUTHORITY=/root/.xauthMPjGOB
                  Depending on your distro, the .xauth* file might be in a different directory. For example, on Arch, I believe it's:
                  Code:
                  /home/non-root-usersname/.Xauthority
                  Just figure out where the .Xauthority file is for the user that's running X-Windows and set the environmental variable to that for root to run graphical programs from the terminal.

                  I hope this helps other people who come here looking for answers as well.

                  Thanks!

                  Comment

                  • sertex78
                    New Member
                    • Jan 2017
                    • 1

                    #10
                    I fixed by making sure X11 was been forward in ssh_confg file

                    cat /etc/ssh/ssh_confg see if under Host *
                    # ForwardX11 is the to no if it is then sudo vi/etc/ssh/ssh_confg
                    and delete the comment # and set it to yes then shift ZZ and try again.

                    Comment

                    Working...