Headless on
Unix
On Unix, you must have an X-Window to write (showPlot) the plot to. This is done
using a Virtual XWindow, such Xvfb. The programs treat this as a normal
XWindow that they are writing graphics to. Like the PC, you run the scripts as
normal, although you don’t need to set at location:
plot = Plot.newPlot()
plot.setSize(600, 500)
…
plot.showPlot()
…
plot.saveToPng("/tmp/myPlot.png")
plot.close()
For more information, refer to:
http://www.x.org/archive/X11R6.8.2/doc/Xvfb.1.html
On Unix it is generally advantageous to use the same script to run in an interactive mode as well as a batch mode. This can be accomplished by checking to see if the DISPLAY environment variable is set. If it isn’t, then check that Xvfb is running and set the DISPLAY variable to “:1.0”. For example:
#!/bin/ksh
# ******************************************************************
if [ "$DISPLAY" = "" ]
then
XvfbRunning=`ps -ef | grep Xvfb | grep -v grep | wc -l | sed -e "s/ //g"`
if [ $XvfbRunning -gt 0 ]
then
export DISPLAY=":1.0"
printf "\nWARNING : Using virtual display – “
printf "no graphics will be visible.\n\n"
else
printf "\nWARNING : Virtual display server is not running."
printf "\n Set DISPLAY variable or start Xvfb.\n\n"
return -1
fi
fi
# ******************************************************************
# Execute the program here….