Python subprocess.run不接受makensis.exe的/ D参数

时间:2018-06-29 13:53:42

标签: python python-3.x subprocess

我有一个NSIS脚本,该脚本接受参数$ {appname}并根据给定名称创建安装程序,该nsis脚本是从python脚本调用的,该脚本也执行其他操作。这是我用来调用NSIS脚本的代码

def run_nsis_process(self,product_name,script, logger):
    NSIS_PATH='C:/Program Files (x86)/NSIS'    
    try:                            
        nsis_args = '/Dappname='+product_name+ ' '+ script                          
        process_completed = subprocess.run(['makensis.exe', nsis_args], shell=True, cwd = NSIS_PATH, universal_newlines = True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, check=True)                              
    except subprocess.CalledProcessError as err:
        logger.error('The makensis.exe subprocess existed with the following code {} \n The makensis.exe produced the following error text{}'.format(err.returncode, err.output))        
    else:                         
        logger.info('Output from NSIS:\n{}'.format(process_completed.stdout))    

这给我一个错误,我没有使用正确的makensis.exe参数。仅作为参考, / Dappname = value 接受该值并将其作为nsis脚本的参数发送到makensis脚本。我得到的错误是

The makensis.exe produced the following error textCommand line defined: "appname=EDMsdk O:\dev/product/NSIS/installer.nsi"     

如果我将subprocess.run替换为os.system

def run_nsis_process(self,product_name,script, logger):
    NSIS_PATH='C:/Program Files (x86)/NSIS'    
    try:                            
        nsis_args = '/Dappname='+product_name+ ' '+ script              
        nsis_cmd = 'makensis.exe /Dappname='+product_name+ ' '+ script                                
        #process_completed = subprocess.run(['makensis.exe', nsis_args], shell=True, cwd = NSIS_PATH, universal_newlines = True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, check=True)                              
        os.system(nsis_cmd)            
    except subprocess.CalledProcessError as err:
        logger.error('The makensis.exe subprocess existed with the following code {} \n The makensis.exe produced the following error text{}'.format(err.returncode, err.output))        
    else:                         
        logger.info('Output from NSIS:\n{}'.format(process_completed.stdout))    

一切正常,我得到了安装程序可执行文件。

我不知道我在做什么错,有什么建议

欢呼

es

1 个答案:

答案 0 :(得分:2)

尝试这个

def run_nsis_process(self,product_name,script, logger):
    NSIS_PATH='C:/Program Files (x86)/NSIS'    
    try:                            
        nsis_args = ['/Dappname=', product_name, script]                          
        process_completed = subprocess.run(['makensis.exe'] + nsis_args, shell=True, cwd = NSIS_PATH, universal_newlines = True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, check=True)                              
    except subprocess.CalledProcessError as err:
        logger.error('The makensis.exe subprocess existed with the following code {} \n The makensis.exe produced the following error text{}'.format(err.returncode, err.output))        
    else:                         
        logger.info('Output from NSIS:\n{}'.format(process_completed.stdout))

问题是您传递了一个参数