我對Python仍然很陌生,現在仍然對自己能做的所有事情都很滿意。我目前正在製作一個小應用程序來幫助我工作。它有一個圖形菜單,可以讓我選擇在PC上安裝的應用程序。我遇到的問題是一些按鈕有兩個安裝程序(32和64位)。我需要程序在開始下一個之前等待一個完成。我該怎麼做呢?如何在Python中一個接一個地運行多個可執行文件
下面的代碼...
def retranslateUi(self, Form):
Form.setWindowTitle(_translate("Form", "Form", None))
self.label.setText(_translate("Form", "What would you like to install?", None))
self.adobe_reader.setText(_translate("Form", "Adobe Reader", None))
self.flash.setText(_translate("Form", "Flash", None))
self.java_7.setText(_translate("Form", "Java 7", None))
self.java_8.setText(_translate("Form", "Java 8", None))
self.adobe_reader.clicked.connect(self.adobe)
self.flash.clicked.connect(self.flash13)
self.java_7.clicked.connect(self.java7)
self.java_8.clicked.connect(self.java8)
def adobe(self):
os.startfile("C:\\Users\\Erik\\Desktop\\install_reader_11.exe")
def flash13(self):
os.startfile("C:\\Users\\Erik\\Desktop\\install_flash_13_IE.exe")
os.startfile("C:\\Users\\Erik\\Desktop\\install_flash_13_nonIE.exe")
def java7(self):
os.startfile("C:\\Users\\Erik\\Desktop\\install_java-7u71-x32.exe")
os.startfile("C:\\Users\\Erik\\Desktop\\install_java-7u71-x64.exe")
def java8(self):
os.startfile("C:\\Users\\Erik\\Desktop\\install_java-8u25-x32.exe")
os.startfile("C:\\Users\\Erik\\Desktop\\install_java-8u25-x64.exe")
下面是編輯的代碼後,我從史蒂夫的變化......也是錯誤的消息,我得到的蟒蛇終端運行安裝程序(這似乎工作崗位)。
def adobe(mycmd):
mycmd = r"C:\Users\Erik\Desktop\install_reader_11.exe"
try:
retcode = call(mycmd,shell = True)
if retcode < 0:
print >>sys.stderr, "Child was terminated by signal", -retcode
else:
print >>sys.stderr, "Child returned", retcode
except OSError as e:
print >>sys.stderr, "Execution failed:", e
retcode = -1
return retcode
def flash13(mycmd):
mycmd = r"C:\Users\Erik\Desktop\install_flash_13_IE.exe"
try:
retcode = call(mycmd,shell = True)
if retcode < 0:
print >>sys.stderr, "Child was terminated by signal", -retcode
else:
print >>sys.stderr, "Child returned", retcode
except OSError as e:
print >>sys.stderr, "Execution failed:", e
retcode = -1
return retcode
錯誤消息...
print >> sys.stderr, "Child returned", retcode
TypeError: unsupported operand type(s) for >>: 'builtin_function_or_method' and
'_io.TextIOWrapper'
謝謝!
感謝您的答覆。當我嘗試用subprocess.call啓動一個exe文件時,我得到了這個 - 「操作系統錯誤:[WinError 740]請求的操作需要提升」 我假設這意味着他們需要管理員權限?我是我個人電腦上的管理員,通常沒有問題。 – sloppyfrenzy 2014-11-04 17:37:04
@sloppyfrenzy奇怪。當我嘗試安裝程序時,安裝程序正常啓動,要求用戶提升權限。你可以以管理員身份啓動你的python腳本,但這不是很優雅。 – 2014-11-04 17:44:07
奇怪。我正在運行Win 8。1如果這有什麼區別。當我右鍵單擊python文件時,我沒有看到以管理員身份運行的選項。子進程比一般的操作系統更好用嗎? – sloppyfrenzy 2014-11-04 18:15:28