简体   繁体   English

subprocess.check_output给Windows错误

[英]subprocess.check_output gives windows error

I was trying to run this file named develop.py written in python. 我正在尝试运行此用python编写的文件develop.py But it gives error. 但这会带来错误。 Here is my code: 这是我的代码:

import base64
import getpass
import os
import subprocess
import sys

credentials = subprocess.check_output([
    'openssl',
    'aes-256-cbc',
    '-d',
    '-in',
    'credentials.development'
    ], shell=True)

env = os.environ.copy()
env['CREDENTIALS'] = credentials
env['CONFIG'] = 'config.yaml.development'
env['ENVIRONMENT'] = 'development'

subprocess.check_call(['grunt', 'web:develop'], env=env)

Here is the result when I run the file: 这是运行文件时的结果:

 E:\QA\QA>python develop.py
    'openssl' is not recognized as an internal or external command,
    operable program or batch file.
    Traceback (most recent call last):
        File "develop.py", line 13, in <module>
           ], shell=True)
        File "C:\Python27\lib\subprocess.py", line 219, in check_output
            raise CalledProcessError(retcode, cmd, output=output)
        subprocess.CalledProcessError: Command '['openssl', 'aes-256-cbc', 
 '-d', '-in', 'credentials.development']' returned non-zero exit status 1

Environment: 环境:
Windows 10 (64 bit) Windows 10(64位)
Python 2.7 Python 2.7

How to fix this ?? 如何解决这个问题?

I think this is a path problem rather than a Python problem. 我认为这是路径问题,而不是Python问题。 The error mentioned is found when Windows cannot find the command you are after. Windows无法找到您要执行的命令时,将发现提到的错误。

In this case the command openssl . 在这种情况下,命令openssl

If openssl is not added to path or a file path to it is not specified then it would produce this error. 如果未将openssl添加到path或未指定文件路径,则将产生此错误。

You should therefore check that the path has been added to path environment variable, then add it if it has not. 因此,您应该检查路径是否已添加到path环境变量,如果尚未添加,请添加它。

that mean One of this Commandes : 这意味着该命令之一:

'openssl',
'aes-256-cbc',
'-d',
'-in',
'credentials.development'

dont Exist in openssl 在openssl中不存在

But if you try this: 但是,如果您尝试这样做:

import base64
import getpass
import os
import subprocess
import sys


credentials = subprocess.check_output(['dir'], shell=True)
env = os.environ.copy()
env['CREDENTIALS'] = credentials
env['CONFIG'] = 'config.yaml.development'
env['ENVIRONMENT'] = 'development'
subprocess.check_call(['grunt', 'web:develop'], env=env)

with dir , it will work perfectly bcz the Command exist 使用dir,它将完美地运行bcz命令存在

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

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