Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在python中启动程序时如何使用标志/启动参数?_Python_Python 3.3 - Fatal编程技术网

在python中启动程序时如何使用标志/启动参数?

在python中启动程序时如何使用标志/启动参数?,python,python-3.3,Python,Python 3.3,我正在尝试创建一个程序,该程序将启动带有标志的livestreamer.exe(-example),但无法确定如何执行此操作 在windows中使用内置的“运行”功能时,我键入以下内容: livestreamer.exe twitch.tv/streamer best 以下是我目前为止的python代码: import os streamer=input("Streamer (full name): ") quality=input("""Quality: Best High Medium L

我正在尝试创建一个程序,该程序将启动带有标志的livestreamer.exe(-example),但无法确定如何执行此操作

在windows中使用内置的“运行”功能时,我键入以下内容:
livestreamer.exe twitch.tv/streamer best

以下是我目前为止的python代码:

import os

streamer=input("Streamer (full name): ")
quality=input("""Quality:
Best
High
Medium
Low
Mobile
: """).lower()
os.chdir("C:\Program Files (x86)\Livestreamer")
os.startfile("livestreamer.exe twitch.tv "+streamer+" "+quality)
据我所知,代码正在查找一个名为livestreamer.exe(FileNotFoundError)的文件,但其中包含所有其他代码。有人知道如何启动内置参数的程序吗?谢谢。

怎么样?比如:

import subprocess
subprocess.call(["livestreamer.exe", "streamer", "best"])
使用
os.system()
而不是os.file()。没有名为“livestreamer.exe twitch.tv”+拖缆+“”+质量的文件

同样
os.system()
不受鼓励,请改用
subprocess.Popen()
Subprocess.Popen()
语法看起来更复杂,但更好,因为一旦知道了
Subprocess.Popen()
,就不需要其他任何东西了
subprocess.Popen()
替换了分散在其他三个Python模块中的其他几个工具(
os.system()
只是其中之一)

如果有帮助,可以将
subprocess.Popen()
看作是一个非常灵活的
os.system()
一个例子:

sts = os.system("mycmd" + " myarg")
以下情况也适用:

sts = Popen("mycmd" + " myarg", shell=True).wait()

sts = Popen("mycmd" + " myarg", shell=True)
sts.wait()

来源:

谢谢,你的操作系统(“livestreamer.exe twitch.tv/“+streamer+”“+quality”)可以使用它。我现在将使用Popen函数,看看是否可以使用它。wait的作用是什么?是否需要包含?
wait()
等待Popen进程完成,在我看到时阅读更多内容,例如,如果我输入了一个没有流的拖缆,并且命令文件没有打开,我在.wait函数之后键入的任何代码会立即运行吗?我认为这对于twitch上有多个通道的宽带网络来说是一个好方法。为什么不呢你试着自己做这件事;-还考虑阅读18.1.2。谢谢你的评论,但是我不太确定如何让这个工作,而Azwr在上面工作了,隐藏了背景中打开的CMDE EXE。