# How to view an image from command line?

I'm running mathematica in command line mode, but I need to view a graph/image, so I'd like to open an image with an X11 window to inspect an image:

Is there an easy way or built-in command to to this?

Update:

This differs from the post Mr. Wizard references, becaause the terminal is running remotely in ssh:

This is how I do it in the terminal usually:

but doesn't work from within mathematica:

• What does $DisplayFunction return on the command line? – J. M. is away Jul 26 '16 at 16:44 • One easy way to do it is to export the file, then have the system open it. i.stack.imgur.com/Okn2s.png – Jason B. Jul 26 '16 at 16:50 • Would you please clarify how this differs from (48239)? – Mr.Wizard Jul 26 '16 at 17:24 •$DisplayFunction is Identity – M.R. Jul 26 '16 at 17:38
• Then you can modify it so that graphical output is redirected to e.g. stdout. What OS are you on? – J. M. is away Jul 26 '16 at 17:40

Might be relevant, but this is something I use that uses StartProcess and ProcessConnection.

xShow[expr_] := Module[{pr = StartProcess[{"display", "png:fd:0"}]},
WriteLine[ProcessConnection[pr, "StandardInput"],
ExportString[expr, "PNG"]];
]


then

Plot3D[Sinh[x]Sinc[y],{x,0,Pi},{y,0,Pi}]//xShow


results in:

This pipes the output to the program display.

I wanted to use this as the $DisplayFunction, but that doesn't cover things like GeoGraphics or other functions that don't use $DisplayFunction, and Plot does some strange doubling (you first get a blank plot and then a plot with the function).

A clever use of $Post could be used rather than my Postfix use. I always use Mathematica from the command line and have usually done display by setting the file init.m in Library/Mathematica/...Kernel/ to the script below. This works on a Mac; it writes the graphics to a pdf file, then displays it. Unfortunately, in Math 11 some of the graphics displays no longer use$DisplayFunction (e.g. ListPlot, Show, ...) and I haven't found a good workaround yet. But the code below works well for Plot, Plot3D, etc.

(*-----------Graphics for command line Mathematica ----------------*)
(*  Install this file in Math../Configuration/Kernel/init.m *)
(*  It may be necessary to create this directory *)
(*  Writes images as PDF files to /tmp/math.xx; then uses Preview to show them *)

Begin["SystemPrivate"]  ;
MaxImages = 100;
ImageNumber = 0;
Unprotect[ $DisplayFunction]; Clear[$DisplayFunction]; $Display = {};$DisplayFunction := Block[{fid,str},
fid="/tmp/math."<>ToString[ImageNumber]<>".pdf";
str=Export[fid, #,"pdf"];
Run["open -a Preview "<>fid<>" &"];
ImageNumber = Mod[ImageNumber+1,MaxImages];
#]&;
End[];