質問

I am trying to automate the installation of a specific program using Sikuli and scripts on Windows 7. I needed to start the program installer and then used Siluki to step through the rest of the installation. I did this using Python 2.7

This code works as expected by creating a thread, calling the subprocess, and then continuing the main process:

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()

This code does not operate as desired. It will start the installer but then hang:

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()

I understand that subprocess.call will wait for the process to terminate. Why does that prevent the main thread from continuing on? Should the main continue execution immediately after the process call?

Why is there such a difference in behaviors?

I have only just recently started using threads C.

役に立ちましたか?

解決

You're calling i.run(), but what you should be calling is i.start(). start() invokes run() in a separate thread, but calling run() directly will execute it in the main thread.

他のヒント

First.

you need to add the command line parameters to your install command to make it a silent install.. http://msdn.microsoft.com/en-us/library/aa372024%28v=vs.85%29.aspx the subprocess is probably hung waiting for an install process that will never end because it is waiting for user input.

Second.

if that doesn't work.. you should be using popen and communicate How to use subprocess popen Python

Third.

if that still didn't work, your installer is hanging some where and you should debug the underlying process there.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top