Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/339.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 subprocess.run不接受makensis.exe的/D参数_Python_Python 3.x_Subprocess - Fatal编程技术网

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

Python subprocess.run不接受makensis.exe的/D参数,python,python-3.x,subprocess,Python,Python 3.x,Subprocess,我有一个NSIS脚本,它接受一个参数${appname},并根据给定的名称创建一个安装程序。NSIS脚本是从python脚本调用的,python脚本还执行其他操作。这是我用来调用NSIS脚本的代码 def run_nsis_process(self,product_name,script, logger): NSIS_PATH='C:/Program Files (x86)/NSIS' try: ns

我有一个NSIS脚本,它接受一个参数${appname},并根据给定的名称创建一个安装程序。NSIS脚本是从python脚本调用的,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

试试这个

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))
问题是您传递了一个参数

请尝试此参数

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))

问题是,您传递了一个参数

谢谢,做了一个小的修复,nsis_args=['/Dappname='+product_name,script],它成功了,前一个参数正在寻找一个以product_name作为名称的脚本。感谢againThanks,做了一个小修复,nsis_args=['/Dappname='+product_name,script],它成功了,前一个是寻找一个以product_name作为名称的脚本。再次感谢