1
votes

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
Care to elaborate what "It does not work" means? Please provide the full traceback of any errors. - Sven Marnach
What is the output of os.system('/usr/bin/which dot')? - Emilio Silva
Then dot is on your path, now try os.system('dot -v -Tpng graph.dot -o graph.png') (that is, use -v for verbose). - Emilio Silva
@EmilioSilva it does not create file graph.png ( if I type in terminal this command then it creates graph.png) - ashim
@capoluca, the -v option is to see if dot gives some explanation as to why it does not create it. - Emilio Silva

1 Answers

3
votes

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