繁体   English   中英

Popen命令失败,返回码为1

[英]Popen command fails with returncode 1

奇怪的是,当django调用以下代码时, Popen返回带有空err returncode=1 但是当我手动运行该程序时,它可以正常工作。 由于err为空,我不知道如何调试。 这是我的代码(将pptx转换为pdf的docsplit):

from subprocess import Popen, PIPE

def execute_commands(commands):
    for command in commands:
        # I know the consequences of shell=True
        process = Popen(command, shell=True, stdout=PIPE, stderr=PIPE)
        try:
            out, err = process.communicate()
            errcode = process.returncode
        except (KeyboardInterrupt, SystemExit):
            process.terminate()
            process.wait()
            raise

        if errcode != 0:
            raise Exception('ErrorCode %s: %s' % (str(errcode), err))

if __name__ == '__main__':
    commands = ["/usr/bin/docsplit pdf --output %s %s" % ('test.pdf', 'test.pptx')]
    execute_commands(commands)

我的环境是:

  • Python 2.7.3
  • 的Django 1.4.4
  • Ubuntu 12.04

该命令在命令行中“运行正常”,但是您是否实际检查过它是否返回成功? 可能不会。 echo $? 手动执行后说?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM