views:

22

answers:

1

Hi,

I'm using subprocess.Popen and getting IOErrors when running under mod_wsgi. The following code will work in a python term, or a django runserver, and under mod_python. If you put it under mod_wsgi (v2), it fails: (2, 'No such file or directory') I have tried many variations involving using subprocess.PIPE. I have tried to redefine stdout, and to use the httpd directives to turn off mod_wsgi's complains of stdout usage. I recently tried upgrading to version 3.

import subprocess

input_file = 'test.html'

p = subprocess.Popen(['htmldoc','-f', 'output.pdf', '--book', input_file])

p.communicate()

len(open('output.pdf').read())

My test effort is going to be to move back to mod_python, and see if the problem goes away. I'd like to know if anyone else has done this and can shed some light on this problem.

A: 

That error message means that Popen can't find htmldoc. Check your $PATH environment variable through os.environ['PATH'] and make sure that htmldoc is installed in one of the paths there.

Alternatively, you can call Popen using an absolute path. For example,

subprocess.Popen(['/usr/bin/htmldoc', ...
Dietrich Epp
You should never rely on PATH for finding executables in a web application. Always use an absolute path. Same goes for the path to the output file. You must do this as the current working directory can be anything and so relative paths are a really bad idea.
Graham Dumpleton
The path `"htmldoc"` is not really a relative path, and the current working directory has no effect on whether it works (unless you're foolhardy enough to put `.` in `PATH`). The advantage of using `htmldoc` instead of `/usr/bin/htmldoc` is that you might want to install your own version, in which case it would be placed in `/usr/local/bin/htmldoc`.
Dietrich Epp
Why not defined a root path in a settings file to a directory full of your utilities, like htmldoc. Then reference them relatively within your app. Best of both worlds. Also downstream dev to spec location of tools. BTW, thanks for answer my question Deitrich
gene