【发布时间】:2016-09-11 08:11:37
【问题描述】:
重复编辑:不,我这样做了,但它不想启动 Firefox。 我正在做一个 cortana/siri 助手的东西,我想让它在我说什么的时候打开一个网络浏览器。所以我已经完成了 if 部分,但我只需要它来启动 firefox.exe 我尝试了不同的东西,但我得到了一个错误。这是代码。请帮忙!它适用于打开记事本,但不适用于 firefox..
#subprocess.Popen(['C:\Program Files\Mozilla Firefox\firefox.exe']) opens the app and continues the script
#subprocess.call(['C:\Program Files\Mozilla Firefox\firefox.exe']) this opens it but doesnt continue the script
import os
import subprocess
print "Hello, I am Danbot.. If you are new ask for help!" #intro
prompt = ">" #sets the bit that indicates to input to >
input = raw_input (prompt) #sets whatever you say to the input so bot can proces
raw_input (prompt) #makes an input
if input == "help": #if the input is that
print "*****************************************************************" #says that
print "I am only being created.. more feautrues coming soon!" #says that
print "*****************************************************************" #says that
print "What is your name talks about names" #says that
print "Open (name of program) opens an application" #says that
print "sometimes a command is ignored.. restart me then!"
print "Also, once you type in a command, press enter a couple of times.."
print "*****************************************************************" #says that
raw_input (prompt) #makes an input
if input == "open notepad": #if the input is that
print "opening notepad!!" #says that
print os.system('notepad.exe') #starts notepad
if input == "open the internet": #if the input is that
print "opening firefox!!" #says that
subprocess.Popen(['C:\Program Files\Mozilla Firefox\firefox.exe'])
【问题讨论】:
-
使用
firefox.exe的绝对路径。 -
记事本通常在 PATH 变量下的 system32 文件夹中,但 firefox 不太可能。
-
user3549596 什么意思?这是路径:C:\Program Files\Mozilla Firefox\firefox.exe
-
...至少显示实际错误!只是默默地无法打开浏览器窗口吗?它是否抛出异常?哪个例外?等等。如果您的错误与输入处理没有任何关系,则根本不需要显示有关输入处理的代码;把那些零件拿出来。