python调用可执行文件,等待生成文件,然后添加或重命名_completed.xml

时间:2018-09-21 00:54:33

标签: python-3.x subprocess popen

我想从python调用可执行文件,以等待进程生成文件 文件的返回名称+ _completed,例如example.xml是可执行文件生成的文件,然后以_complete返回生成的文件的名称 因此它应该返回example_complete.xml,这是我的代码

import subprocess
import requests
import xmltodict

xml_input=r'c:\workingfolder\customers.xml'
form_inputs='a:b:c'

def run_excel_again(xml_input,form_inputs):
  subprocess.Popen(['c:\\path to my excel.exe',xml_input,'/c',form_inputs])
 #check if file is created takes about a minute to generate file
 #subprocess.wait()-- is this possible how to check if the file generation 
  #   is completed --pass filename_completed.xml to 
  #another function  run_excel_again2(filename_completed.xml) 
   print('processing completed')
 return(filename.xml,filename_completed.xml)

run_excel_again(xml_input,form_inputs)

1 个答案:

答案 0 :(得分:1)

def run_excel_again(xml_input,form_inputs):
p= subprocess.Popen(['c:\\path to my excel.exe',xml_input,'/c',form_inputs])
#check if file is created takes about a minute to generate file
p.wait(timeout=none)-- Adding this statement worked for me 
#   is completed --pass filename_completed.xml to 
#another function  run_excel_again2(filename_completed.xml) 
print('processing completed')
return(filename.xml,filename_completed.xml)

它只需要这一行代码

p.wait(timeout=none)