从POPEN意外的行为,一旦Web应用程序部署与Apache [英] Unexpected behavior from Popen once web app is deployed with apache

查看:115
本文介绍了从POPEN意外的行为,一旦Web应用程序部署与Apache的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用子进程来看待从git的目录中的日志一些code。我的code时,似乎在本地的Django开发环境中执行工作的罚款。但是一旦部署(与Apache / mode_wsgi)从标准输出读取输出()回来空。我的开发和生产的机器都是一样的,现在,我也尝试确保每个文件是可读的。

没有任何人有一个想法,为什么POPEN没有返回这里一旦部署任何输出?谢谢你。

 高清getGitLogs(项目名,SEARCHTERM =无,因为):
    os.chdir(os.path.join(settings.SCM_GIT,项目名))
    CMD =混帐日志--since {0} -p.format(自)
    P = subprocess.Popen(CMD,壳= TRUE,标准输入= subprocess.PIPE,标​​准输出= subprocess.PIPE,标​​准错误= subprocess.STDOUT,close_fds = TRUE)
    输出= p.stdout.read()
    ###在这里输出回来预期在开发环境,但在空一旦部署
    返回filterCommits(parseCommits(输出),SEARCHTERM)


解决方案

  1. 链中的 CHDIR 作为命令的一部分(即 CD /富/酒吧/动物园

  2. 传递完整路径混帐

所以,你的命令将结束 CD /富/酒吧/动物园和放大器;&安培;在/ usr /斌/ git的日志--since

I have some code that uses subprocess to look at the logs from a git directory. My code seems to work fine when executed in a local django dev environment. Once deployed however (with Apache / mode_wsgi) the output from stdout read() comes back empty. My development and production machine are the same right now, and I also tried making sure every file was readable.

Does anybody have an idea why Popen is not returning any output once deployed here? Thanks.

def getGitLogs(projectName, searchTerm=None, since):
    os.chdir(os.path.join(settings.SCM_GIT, projectName))
    cmd = "git log --since {0} -p".format(since)
    p = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True)
    output = p.stdout.read()
    ### here output comes back as expected in dev environment, but empty in once deployed
    return filterCommits(parseCommits(output), searchTerm)

解决方案

  1. Chain your chdir as part of your command (ie, cd /foo/bar/zoo)
  2. Pass the full path to git

So your command would end up cd /foo/bar/zoo && /usr/bin/git log --since

这篇关于从POPEN意外的行为,一旦Web应用程序部署与Apache的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆