任务:我需要使用Sikuli重新启动explorer.exe进程。
我的解决方案是创建批处理文件" RestartExplorerProcess.bat":
@echo off
echo Your desktop is being restored, Please wait. . .
ping -n 5 127.0.0.1 > NUL 2>&1
echo Killing process Explorer.exe. . .
taskkill /f /im explorer.exe
cls
echo Explorer.exe is killed!
echo.
echo Your desktop is now loading. . .
ping -n 5 127.0.0.1 > NUL 2>&1
echo.
ping -n 5 127.0.0.1 > NUL 2>&1
start %windir%\explorer.exe
echo Explorer.exe was successfully started!
exit
然后我用它来调用它:
subprocess.Popen(Path)
问题是我需要在进一步操作之前等待重启explorer.exe。 我找到了3个解决方案:
1. p = subprocess.Popen(Path)
p.wait()
2. subprocess.check_call(Path)
3. os.system(Path)
但是所有这些都有相同的效果--Sikuli没有显示任何错误而只是挂起。也许我错了,但看起来在重启explorer.exe进程时我松了一些引用,关于完成批处理文件的事件永远不能执行。
所以我的问题是:
答案 0 :(得分:0)
使用Sikuli启动/重启Firefox(或Internet Explorer)我使用以下内容:
# Path to Firefox executable:
PathFirefox = r"C:\Program Files (x86)\Mozilla Firefox\firefox.exe"
# Open Firefox
App.open(PathFirefox)
要检查应用是否处于活动状态,您可以编写一个定义来检查应用是否处于活动状态。
例如:
def appActive(appName):
call = 'TASKLIST', '/FI', 'imagename eq %s' % appName
# Get the tasklist result
proc = subprocess.Popen(call, shell=True, stdout=subprocess.PIPE)
# Trimming lines with information
output = proc.communicate()[0].strip().split('\r\n')
# If TASKLIST returns multiple lines, it is running.
if len(output) > 1 and appName in output[-1]:
print('Result: "%s" is running!' % appName)
return True
else:
print('Result: "%s" is NOT running!' % appName)
return False
# Check if Eclipse and Firefox are running:
appActive('eclipse.exe')
appActive('firefox.exe')
答案 1 :(得分:0)
你可以创建2个蝙蝠:1个杀死,第二个重启。之后,您可以检查是否存在桌面图像,这是一个功能。
def restarExplorer():
desktop_home = "your/file/location/desktop_home.png"
killExplorer = App("your/file/location/killExplorer.exe")
restartExplorer = App("your/file/location/restartExplorer.exe")
killExplorer.open()
sleep(3) # waiting 3
restartExplorer.open()
while not exists(desktop_home): # check if desktop button appears
sleep(1) # keep waiting
continue..