Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将powershell命令作为json字符串传递到子进程_Python_Json_Powershell_Subprocess - Fatal编程技术网

Python 将powershell命令作为json字符串传递到子进程

Python 将powershell命令作为json字符串传递到子进程,python,json,powershell,subprocess,Python,Json,Powershell,Subprocess,我有一个json文件,其中包含按优先级排列的安装程序列表。STEP_NAME是安装程序的名称,要求包含首先安装的安装程序列表 步骤定义安装程序的名称,命令是要执行以安装安装程序的powershell命令 { { "STEP_NAME" : "Second_Installer", "REQUIREMENT" : [ { "KEY": "First_Installer",

我有一个json文件,其中包含按优先级排列的安装程序列表。
STEP_NAME
是安装程序的名称,
要求
包含首先安装的安装程序列表

步骤
定义安装程序的名称,
命令
是要执行以安装安装程序的powershell命令

{
 {
        "STEP_NAME" : "Second_Installer",
        "REQUIREMENT" :
        [
            {
                "KEY": "First_Installer",
                "TYPE": "STEP"
            },
            {
                "KEY":  "Powershell -ExecutionPolicy Bypass -Command { cd $env:userprofile\\Installers\\Second_Installer; .\\install.bat; }",
                "TYPE": "COMMAND"
            }
        ]
    },
    {
        "STEP_NAME" : "First_Installer",
        "REQUIREMENT" :
        [                
            {
                "KEY": "Powershell -ExecutionPolicy Bypass -Command { &{cd $env:userprofile\\Installers\\First_Installer; .\\install.bat; }}",
                "TYPE": "COMMAND"
            }
        ]
    }
}
我有一个python脚本,用于检查json文件中的密钥是否已安装。 因此,它必须先安装
第一个安装程序
,然后才能安装
第二个安装程序

我的python代码是:

def run_step(self, step):
    # If step was a Requirement, find the matching STEP_NAME
    for item in self.installer_json_data:
        if item['STEP_NAME'] == step:
            step = item

    for req in step['REQUIREMENT']:
        if self.STEP_DONE[step['STEP_NAME']] == False:
            if req['TYPE'] == self.STEP_TYPES[0]:
                self.run_step(req['KEY'])
            elif req['TYPE'] == self.STEP_TYPES[1]:
                commandExecutor = subprocess.Popen(req['KEY'], shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
                print("Installing "+ step['STEP_NAME'])
                commandExecutor.communicate()
                time.sleep(5)
                while commandExecutor.poll() is None:
                    # Decode default byte stream to utf-8 and replace all un-decodable bytes to handle ISO-8859-1
                    output = codecs.decode(commandExecutor.stdout.readline(), 'utf-8', 'replace')
                    #print(output.strip()) # strip removes trailing \n 
                if commandExecutor.returncode == 0:
                    print("Installed " + step['STEP_NAME'])
                    self.STEP_DONE[step['STEP_NAME']] = True
                else:
                    print('Failed to install ' + step['STEP_NAME'])
                    break
但是在执行脚本之后,它会说安装程序已经安装,而实际上并没有安装

有人能告诉我我做错了什么吗

注意-这些安装程序需要以管理员身份安装