【发布时间】:2016-07-13 10:51:59
【问题描述】:
任务:我需要使用 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 进程时我失去了一些参考,并且关于完成批处理文件的事件永远无法执行。
所以我的问题是:
- 如何使用常用的 Sikuli (Jython) 方法重新启动 explorer.exe 进程?
- 我如何才能等待使用上述任何方法完成我的批处理文件?
【问题讨论】:
-
是什么导致了挂起?
Popen还是p.wait()?如果是p.wait(),则使用默认的wait()函数并指定一个大于启动explorer.exe所需时间的超时。只需在 explorer.exe 重新启动时使用唯一的图像。
标签: windows batch-file jython explorer sikuli