子进程 returns 退出状态 1

Subprocess returns exit status 1

当我 运行 通过子进程执行命令时,我得到退出状态 1,但没有打印或出现错误。

这是我的代码:

    def generate_model(self):
        if not ((self.username == None) or (self.password == None) or (self.database == None)):
            cmd = "python -m pwiz -e %s -H %s -u %s -P %s %s > %s"%(self.engine,self.host,self.username,self.password,self.database,self.database+".py")
            print subprocess.check_call(cmd)
        else:
            raise ValueError

命令在终端打开后要求输入。之后它以 exit status 1

结束

当我 运行 直接在命令提示符下执行相同的命令时它工作正常

默认情况下,

subprocess.check_call() 不会 运行 shell,因此重定向运算符 > 将不起作用。要重定向标准输出,请改为传递 stdout 参数:

with open(filename, 'wb', 0) as file:
    check_call([sys.executable, '-m', 'pwiz', '-e', ...], stdout=file)

相关:.