我正在尝试使用子进程库。
$youtube-dl http://www.youtube.com/watch?v=co5gy_2uOEY
在终端上按预期工作,但在 IDLE 中运行的以下代码片段似乎没有做任何事情。
> os.chdir('/home/andrew')
> line = 'http://www.youtube.com/watch?v=co5gy_2uOEY'
> yt_dl = subprocess.call(['youtube-dl',line])
1
或者,我也尝试过:
> yt_dl = subprocess.Popen(['youtube-dl',line])
但这又回来1
了,也没有做任何事情。这里发生了什么?
编辑:
用双引号换行使其工作,但现在这个子进程挂起。我尝试进行以下更改,但它再次不起作用:
yt_dl = ["youtube-dl","http://www.youtube.com/watch?v=co5gy_2uOEY"]
x = subprocess.Popen(yt_dl, stdout=subprocess.PIPE, stdin=subprocess.PIPE, shell=True)
stdout, stderr = x.communicate()