I have a python program that uses graphviz to generate an svg image that it prints out. When I run that in a shell buffer I see a textual representation of the svg image. I'd like to see instead the generated image. How do I take that text in emacs and get something that shows me the image?

  • Pipe the output of the python program into the standard input of an image display program that can read from stdin (e.g. display which is part of ImageMagick, can read stdin: cat foo.svg | display -)
    – NickD
    Aug 20, 2023 at 18:46
  • Ok, thanks that is helpful. Now I will go look for imageMagick and how to install it.... Aug 20, 2023 at 19:00
  • Check whatever image display program you have available first: display is just one example that should work.
    – NickD
    Aug 20, 2023 at 20:05
  • Yes, it turns out that graphviz writes that image to a file and if I simply open a buffer to that file, emacs displays it (in that buffer). It's not quite as magic as what Jupyter notebooks do, as I have to manually open the file (or fix my comint-send-command to do that for me). If this comment was an answer, I would have accepted it. Sep 9, 2023 at 10:13

1 Answer 1


I am not sure where and how you are running Emacs, but I think graphical Emacs can show the svg image itself also in most cases. Then the following answer is an alternative to the answer by @NickD in the comments.

I am not sure if you need to run the command in a shell buffer per se, but otherwise you could also use the following command (via M-x or create a keybinding):

(defun display-output-as-image (command)
    (read-shell-command (if shell-command-prompt-show-cwd
                            (format-message "Shell command in `%s': "
                          "Shell command: ")
                        nil nil
            (let ((filename
                ((eq major-mode 'dired-mode)
                 (dired-get-filename nil t)))))
              (and filename (file-relative-name filename))))))
  (shell-command command
   (pop-to-buffer "output.svg"))

Then, after calling this command, you can simply type in the command and the image will show in an Emacs buffer.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.