-3

I generated a dot file using Python.

Each time the file is generated, I need to run a script in the Terminal to convert it to a pdf file or an image.

This is the script:

dot -Tpdf somefile.dot -o somefile.pdf

I was wondering if it is possible to execute this script in the current folder, from within my Python code.

JNevens
  • 11,202
  • 9
  • 46
  • 72
  • 1
    The first point in [the guideline on how to ask a question on StackOverflow](http://stackoverflow.com/help/how-to-ask) says that you should search, and research. What have you tried searching/researching so far, before you asked this question? – Amit Kumar Gupta Dec 02 '14 at 08:57

2 Answers2

3

os module allows you to execute custom scripts like this

import os

os.system("dot -Tpdf somefile.dot -o somefile.pdf")

You can find more information here

micgeronimo
  • 2,069
  • 5
  • 23
  • 44
0

better to use subprocess.Popen will have track of error and output:

import subprocess
child = subprocess.Popen(["dot -Tpdf somefile.dot -o somefile.pdf"],stdout=subprocess.PIPE, shell=True)
output,err = child.communicate()
Hackaholic
  • 19,069
  • 5
  • 54
  • 72