收录日期:2020/12/02 10:24:31 时间:2013-03-02 10:10:51 标签:django,apache2,subprocess,mod-wsgi,pdflatex

I'm sorry if this is a duplicate question, but after searching through 3 pages for "django subprocess", I, for one, could not find the answer to my particular problem.

I'm trying to run pdflatex on tex file, but for some reason in Django it doesn't produce anything. It works just fine in a regular python script, though. I've omitted most of the code here, but this is basically the important bit. I'm running this on apache2 with mod_wsgi, and I suspect that it might be an apache permissions related problem, dunno though. Thanks in advance.

import subprocess
test = subprocess.Popen(['pdflatex','/home/sheepz/test.tex'],shell=True, stdout=subprocess.PIPE)
log = open('/home/sheepz/log.log', 'w')
log.write(str(test.communicate()))
log.close()

the content of the file "log.log":

('This is pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009/Debian)\n restricted \\write18 enabled.\n**\n! End of file on the terminal... why?\n', None)

EDIT: The solution for this issue is quite easy. I just want to add it here, so everyone who's having trouble with this, can find it. Basically it involves running the site as a different user rather than www-data using the WSGIDaemonProcess configuration directive. Here is a minimal configuration:

ServerName www.mysite.com
ServerAlias *mysite.com
WSGIDaemonProcess www.mysite.com user=joe group=joe home=/home/joe/
WSGIProcessGroup www.mysite.com

Also, it would be advisable to add WSGIRestrictStdout Off to your httpd.conf, because, as far as I understand, mod_wsgi ignores any process that tries to use stdout. Thanks, Graham.

Specify the absolute path to 'pdflatex' in command. Apache user PATH may not look in same directories as your personal account does. Also, Apache runs as a special user that isn't going to have write access to where you can. Suggest you use mod_wsgi daemon mode and specify that that daemon process runs as you and not the Apache user. Read up documentation on mod_wsgi site as to how to do that.