【发布时间】:2014-04-08 20:55:39
【问题描述】:
我正在尝试使用Sikuli 和 Windows 7 上的脚本自动安装特定程序。我需要启动程序安装程序,然后使用 Siluki 逐步完成安装的其余部分。我使用 Python 2.7 做到了这一点
此代码按预期工作,通过创建线程、调用子进程,然后继续主进程:
import subprocess
from threading import Thread
class Installer(Thread):
def __init__(self):
Thread.__init__(self)
def run(self):
subprocess.Popen(["msiexec", "/i", "c:\path\to\installer.msi"], shell=True)
i = Installer()
i.run()
print "Will show up while installer is running."
print "Other things happen"
i.join()
此代码无法按预期运行。它将启动安装程序,但随后挂起:
import subprocess
from threading import Thread
class Installer(Thread):
def __init__(self):
Thread.__init__(self)
def run(self):
subprocess.call("msiexec /i c:\path\to\installer.msi")
i = Installer()
i.run()
print "Will not show up while installer is running."
print "Other things happen"
i.join()
我了解 subprocess.call 将等待进程终止。为什么这会阻止主线程继续运行?进程调用后main是否应该立即继续执行?
为什么会有这样的行为差异?
我最近才开始使用线程 C。
【问题讨论】:
-
也许管理员权限是问题所在。试试 subprocess.call(['runas', '/user:Administrator', 'c:\path\to\installer.msi'])
-
是否需要在安装命令中添加命令行参数以使其成为静默安装?
标签: python multithreading python-2.7 subprocess