我试图使用西库利和Windows7上的脚本自动安装一个特定的程序,我需要启动程序安装程序,然后使用Siluki逐步完成其余的安装工作。我是用Python2.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将等待进程终止。为什么这会阻止主线程继续运行呢?主进程调用后是否应立即继续执行?
为什么行为有这么大的差别?
我最近才开始使用线程C。
发布于 2014-04-08 21:35:24
您正在调用i.run(),但是应该调用的是i.start()。start()在一个单独的线程中调用run(),但是直接调用run()将在主线程中执行它。
发布于 2014-04-08 21:26:47
第一。
您需要将命令行参数添加到安装命令中,以使其成为静默安装。http://msdn.microsoft.com/en-us/library/aa372024%28v=vs.85%29.aspx子进程可能挂起,等待一个永远不会结束的安装进程,因为它正在等待用户输入。
第二。
如果不起作用..。您应该使用popen并与如何使用子进程popen Python通信。
第三。
如果这仍然不起作用,您的安装程序将挂起一些位置,您应该在那里调试底层进程。
https://stackoverflow.com/questions/22947976
复制相似问题