2

I need to execute shell command in python program (I have ubuntu). More specifically I want to create graph using graphviz in python script. My code is

os.system("dot -Tpng graph.dot -o graph.png")

It does not work, but if I just type dot -Tpng graph.dot -o graph.png in command line then everything is fine. Do you know what the problem? Thank you!

Edit: Does not work means that nothing happens, there are no errors.

Output from dot -v -Tpng graph.dot -o graph.png:

dot - graphviz version 2.26.3 (20100126.1600)
Activated plugin library: libgvplugin_pango.so.6
Using textlayout: textlayout:cairo
Activated plugin library: libgvplugin_dot_layout.so.6
Using layout: dot:dot_layout
Using render: cairo:cairo
Using device: png:cairo:cairo
The plugin configuration file:
    /usr/lib/graphviz/config6
        was successfully loaded.
    render  :  cairo dot fig gd map ps svg tk vml vrml xdot
    layout  :  circo dot fdp neato nop nop1 nop2 osage patchwork sfdp twopi
    textlayout  :  textlayout
    device  :  canon cmap cmapx cmapx_np dot eps fig gd gd2 gif gv imap         imap_np ismap jpe jpeg jpg pdf plain plain-ext png ps ps2 svg svgz tk vml vmlz vrml wbmp x11 xdot xlib
    loadimage   :  (lib) eps gd gd2 gif jpe jpeg jpg png ps svg
1
  • For future coding related questions, post to Stack Overflow. +1 for Python :-)
    – invert
    Mar 3, 2012 at 18:23

2 Answers 2

1

I figured out the problem. I should close file graph.dot before executing the command.

0

Strange, I just tried with the same command and it gave me the expected output (that graph.dot doesn't exist) Are you sure you have

import os

? Also, are you sure that this piece of code that executes the 'dot' command isn't in a untrue condition (in an 'if' statement that is untrue, so the piece of code after this never executes)?

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .