好的,谢谢大家的帮助。我有第二个问题。我在观看视频流时需要聊天,并且可能会使用irc。服务器为irc.twitch.tv
,频道与livestreamer名称相同。当我尝试这个代码时,它给了我错误。Python子进程和raw_input
# -*- coding: latin-1 -*-
import subprocess
print(35*"+")
name = raw_input("Livestreamer name\n")
hostVideo = subprocess.Popen(['livestreamer', 'twitch.tv/'+name, 'best'], stdout = subprocess.PIPE).communicate()[0]
hostIrssi = subprocess.Popen(['irssi --connect=irc.twitch.tv --password=oauth:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx --nick=nickname'], stdout = subprocess.PIPE).communicate()[0]
print hostVideo
print hostIrssi
这是错误我得到了什么
Traceback (most recent call last):
File "Livestreamer.py", line 7, in <module>
hostIrssi = subprocess.Popen(['irssi --connect=irc.twitch.tv --password=oauth:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx --nick=nickname'], stdout = subprocess.PIPE).communicate()[0]
File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1327, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
而且如果可能的话,告诉我如何让它加入自动右声道。
我大后
我喜欢看抽搐串流和我想要做的脚本,询问livestreamer名,然后发送命令到终端。 Livestreamer命令就像
livestreamer twitch.tv/user best
所以脚本必须用户之后添加livestreamer命令后,“twitch.tv/”和“最佳”。 我的代码如下所示:
# -*- coding: latin-1 -*-
import subprocess
user = raw_input("Livestreamers name:\n")
livestreamer = "livestreamer twitch.tv/"
host = subprocess.Popen(['livestreamer', 'twitch.tv/', user, 'best'], stdout = subprocess.PIPE).communicate()[0]
print host
输出是
livestreamer: error: unrecognized arguments: best
如果有人知道什么是错的,我好高兴。也对不起我的坏英语。 :)
无关:您可以替换'output = subprocess.Popen(..)。communicate(..)[0] ''output = subprocess.check_output(['livestreamer','twitch.tv /'+ sanitize(user),'best'])'或者你不需要输出:'subprocess.check_call([.. ],标准输出= DEVNULL)'。尽管看起来'livestreamer'没有产生太多的输出,因此在'communicate()'/'check_output()'函数中存储内存中整个子进程的输出没有问题。 – jfs
你应该把*“OSError:[Errno 2]没有这样的文件或目录”*问题到一个单独的问题。尽管答案与*“livestreamer:error:无法识别的参数:最佳”错误相同,即:一个命令行参数 - >一个列表项。 – jfs