标签:mat 进程 sts sleep port ati arc break walk
1 #-*-coding:utf8-*- 2 import os 3 import subprocess 4 import time 5 6 #查找windows所有盘符名称 7 information = os.popen("wmic LOGICALDISK get name").read().split("\r\n") 8 code = [] 9 for inform in information: 10 if ‘:‘ in inform: 11 code.append(inform.strip()) 12 print code 13 14 #查找指定文件名称和查找范围的文件路径 15 def search(name,path): 16 name = name.lower() 17 for root,dirs,files in os.walk(path): 18 for file in files+dirs: 19 if name in file.lower(): 20 return os.path.join(root,file) 21 return -1 22 #遍历所有盘符,直到找到StataMP-64.exe文件 23 for path in code: 24 stata_path = search(‘StataMP-64.exe‘,path+‘\\‘) 25 if stata_path != -1: 26 break 27 print stata_path 28 #运行指定的其他类型的程序,如do文件 29 do_file = os.path.abspath("test.do") 30 cmd = [stata_path,‘do‘,do_file] 31 child = subprocess.Popen(cmd) 32 while True: 33 if os.path.exists("test.csv"): 34 time.sleep(1) 35 child.kill() #杀死子进程 36 print ‘Success‘ 37 break
标签:mat 进程 sts sleep port ati arc break walk
原文地址:https://www.cnblogs.com/jpapplication/p/9789029.html