A /dev/null equivilent for DISPLAY when the display is just noise
Asked Answered
Y

6

24

I'm running a java app which creates a visual display of some of the things it is doing, while it is doing it. However, I'm want to run this in a script that won't have a display to attach to. In the current environment, there isn't even a DISPLAY environment variable set. I tried to simply set my DISPLAY to :0.0. But that doesn't exist. I don't really care about the display. I just want the app to process the files silently.

Since I can't just turn the display off(not my app), I'm left with trying to get around the need for display.

Is there a black hole that I can send the DISPLAY to? an equivalent to /dev/null?

I searched around for a bit on the web, but the words I could think of to use: "display" "null" "disregard" etc are all two generic to get me to an answer.

This is the middle of a larger script, so I want the rest of the output to stdout to be available.

Yurev answered 7/5, 2009 at 13:44 Comment(0)
A
18

There's a headless X server called Xvfb. It's basically what you need since it accepts X clients but basically does nothing with the data from them. From that linked page (slightly paraphrased):

Xvfb, the X virtual framebuffer, is a display server implementing the X11 display server protocol.

In contrast to other display servers, Xvfb performs all graphical operations in memory without showing any screen output.

From the point of view of the client, it acts exactly like any other X display server, serving requests and sending events and errors as appropriate. However, no output is shown.

This virtual server does not require the computer it is running on to have a screen or any input device. Only a network layer is necessary.

If you can't find that, then another possibility would be to use a spare PC with a full CygWin install. CygWin comes with a full-blown X server which you could connect your application to (and just ignore it). You could even set it up as the corporate /dev/null DISPLAY.

But I'd look into Xvfb first.

Advisedly answered 7/5, 2009 at 13:58 Comment(2)
This worked out really well for me. It is Xvfb. The box isn't mine, but the administrator was nice enough to put it on the box.Yurev
Thank you! I've always wanted to be able to run gschem to produce PDFs and PNGs of my schematics on my build machine, but it hasn't worked without X (which is a pain in the butt). Now with Xvfb there's an X server for it to connect to!Preposition
A
3

Short answer, use:

xvfb-run JAVA_COMMAND_LINE

Depending on your version and flavor of Linux, there may be one line you have to change in xvfb-run to get everything to run.

Angioma answered 7/4, 2017 at 20:48 Comment(0)
L
3

I've been using Xvfb and works very well to run applications which require a X server in ssh sessions.

To complement previous answers, I use two main ways to run Xvfb:

  1. Run Xvfb in a specific port and configure the terminal to use this port:

    Xvfb :10
    export DISPLAY=:10 
    YOUR_COMMAND
    
  2. Use xvfb-run:

    xvfb-run YOUR_COMMAND
    
Lunde answered 6/10, 2021 at 17:41 Comment(1)
Nice! Big shout out for answering a question that is over a decade old! I've come to SO so many times and every little bit of context in all the answers has helped me. So I hope this extra bit helps someone else too.Yurev
G
2

If it's a java program you can use the headless mode to run the application.

Try to run it with -Djava.awt.headless=true parameter, like this if it's a jar file:

java -Djava.awt.headless=true -jar jarfile.jar

More about headless mode...

Genera answered 7/5, 2009 at 14:16 Comment(2)
I did not get a chance to make this approach work. I tried, but received a headless exception still. No doubt if this little app was written right, I could have used this flag.Yurev
@Marc: java.awt.headless=true just tells the JVM that no display is available. Some Java APIs can handle this, and continue working, some cannot, and throw HeadlessException. So whether it works depends on what the program does. See Using Headless Mode in the Java SE Platform(by Artem Ananiev and Alla Redko, June 2006 ) for details.Mayfair
M
1

You can use Xvfb, as noted above. That way, you will never see the output (you can use a tool to take screenshots, though).

http://en.wikipedia.org/wiki/Xvfb http://packages.debian.org/sid/xvfb

Or you could set up a VNC server. Under Linux, a VNC server is implemented as a special X server that can be accessed via VNC, insstead of displaying on a local monitor. That gives you a headless X server, with the added bonus that you can connect to it via VNC just in case you do need to see what's going on.

http://www.tightvnc.com/vncserver.1.html

vncserver is a nice wrapper script for (tight)VNC, which makes starting a VNC server a breeze. Most distros should install it by default.

Mayfair answered 7/5, 2009 at 14:11 Comment(0)
D
0

Can you run a VM on the target machine? Then you could set your DISPLAY to that. Or you could try vnc (currently on a machine which doesn't allow this or I'd try it...).

Dewar answered 7/5, 2009 at 14:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.