【发布时间】:2011-03-18 09:41:57
【问题描述】:
如果这是一个重复的问题,我很抱歉,但是在搜索了 3 页“django subprocess”之后,我,一方面,找不到我的特定问题的答案。
我试图在tex 文件上运行pdflatex,但由于某种原因在 Django 中它不会产生任何结果。不过,它在常规的 python 脚本中工作得很好。我在这里省略了大部分代码,但这基本上是重要的一点。我正在使用 mod_wsgi 在 apache2 上运行它,我怀疑这可能是与 apache 权限相关的问题,但不知道。
提前致谢。
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)
编辑: 这个问题的解决方案很简单。我只是想在这里添加它,所以遇到问题的每个人都可以找到它。基本上它涉及使用WSGIDaemonProcess 配置指令以不同的用户而不是www-data 的身份运行站点。这是一个最小配置:
ServerName www.mysite.com
ServerAlias *mysite.com
WSGIDaemonProcess www.mysite.com user=joe group=joe home=/home/joe/
WSGIProcessGroup www.mysite.com
此外,建议将WSGIRestrictStdout Off 添加到您的httpd.conf,因为据我了解,mod_wsgi 会忽略任何尝试使用stdout 的进程。谢谢,格雷厄姆。
【问题讨论】:
-
您使用什么操作系统?启用 SE Linux?
-
Ubuntu 10.04 LTS,所以默认不安装SELinux。
-
WSGIRestrictStdout 不需要,因为您使用 mod_wsgi 3.X,因为现在默认允许 stdout 访问,因为用户更喜欢编写非便携式 WSGI 应用程序。
-
好的,感谢您的澄清 :)
标签: django apache2 subprocess mod-wsgi pdflatex