18

I would like to display a graph without writing a file first.

Suppose I have a command foo that produces this on standard out:

digraph foogrph {
   a -> b;
   a -> c;
}

What I would like to do is pipe foo into dot and then pipe the results into a command that will display the image in a graphical environment.

foo | dot -Tpng | <display command>

I have found a workaround that involves temporary files. In OSX, I can do the following:

foo | dot -Tpng > temp && open temp

But I still have to remove the file from the filesystem.

How can I display an image that is being written to standard out?

4 Answers 4

17

With ImageMagick's display command, these work on Ubuntu 12.10 (and most likely other OSes, too):

dot abac.dot -Tsvg | display
dot abac.dot -Tpng | display

SVG has the advantage of smoothly scaling with the window (if that's what you want).

Sign up to request clarification or add additional context in comments.

3 Comments

I had to recompile imagemagick on OSX to use X11, I have display working now, but it doesn't read from a pipe correctly. I found a workaround though: display <(echo 'digraph { a->b; b->c; c->d; }' | dot -Tpng)
Another option is to use dotty, examples here at the git wiki
Also the imgcat script that works with iTerm can display the image directly at the terminal, it's pretty sweet :)
3

On Linux you can also just use -Tx11:cairo to display a direct X11 window.

2 Comments

I tried this and this just produced a big white blank window.
okay but how can you display the graph without using a file ?
3

On OSX & iTerm2, you can do the following (assuming imgcat is installed)

dot abac.dot -Tpng | imgcat

enter image description here

Comments

1

To complete the accepted answer (which is totally OK), if one want to also avoid using a .dot file :

echo 'digraph { a -> b }' | dot -Tpng | display

(this is for linux only, also I first tried eog that doesn't seem accepting pngs through pipes)

Adapted from rom the documentation of graphviz command line usage.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.