Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling pandoc from python using subprocess.Popen

I am having problems calling pandoc from python using subprocess.Popen. It all works in the console. Here is the code.

# Test markdown file
here is just a simple markdown file.

Now my python code using that filename is the full path my markdown file:

import subprocess
fileout = os.path.splitext(filename)[0] + ".pdf"
args = ['pandoc', filename, '-o', fileout]
subprocess.Popen(args)

I also tried various ways to capture an error but that didn't work. In the console, however, everything is running fine:

pandoc '[filename]' -o '[fileout]'
like image 229
user2503795 Avatar asked Sep 29 '12 04:09

user2503795


2 Answers

This doesn't answer your question (and you may specifically want/need to call pandoc using subprocess.Popen) but there is a Python wrapper for Pandoc called Pyandoc: see my answer here.

like image 51
Sam Dutton Avatar answered Sep 18 '22 11:09

Sam Dutton


That should work just fine, but you may want to wait for it to finish using subprocess.check_call rather than subprocess.Popen directly:

subprocess.check_call(args)

This also makes sure that it completed successfully. If the status code isn't 0, it will throw an exception.

like image 26
icktoofay Avatar answered Sep 19 '22 11:09

icktoofay