我目前正在尝试使用GNU Parallel,但我并没有成功。安装非常简单。我的目标是运行python脚本youtube-dl的两个并行实例及其相应的参数。使用parallel并执行脚本的正确方法是什么?
并行
parallel 'youtube-dl -w --no-warnings -o "/media/video1.%(ext)s" "http://www.cnn.com/videos/us/2015/11/11/stun-gun-used-on-man-in-police-custody-dies-lawsuit-dnt-brown-tsr.cnn"' 'youtube-dl -w --no-warnings -o "/media/video2.%(ext)s" "http://www.cnn.com/videos/us/2015/11/11/5-year-old-saves-family-from-house-fire.ktla"'
如果在没有并行的情况下单独运行命令,它可以工作:
youtube-dl -w --no-warnings -o "/media/video1.%(ext)s" "http://www.cnn.com/videos/us/2015/11/11/stun-gun-used-on-man-in-police-custody-dies-lawsuit-dnt-brown-tsr.cnn"
youtube-dl -w --no-warnings -o "/media/video2.%(ext)s" "http://www.cnn.com/videos/us/2015/11/11/5-year-old-saves-family-from-house-fire.ktla"
答案 0 :(得分:3)
对于两个流,只需在第一个命令的末尾放一个&符号(&)就可以了。像这样:
youtube-dl -w --no-warnings -o "/media/video1.%(ext)s" "http://www.cnn.com/videos/us/2015/11/11/stun-gun-used-on-man-in-police-custody-dies-lawsuit-dnt-brown-tsr.cnn" &
youtube-dl -w --no-warnings -o "/media/video2.%(ext)s" "http://www.cnn.com/videos/us/2015/11/11/5-year-old-saves-family-from-house-fire.ktla" &
# Wait for both downloads to finish
wait
如果你想使用GNU Parallel ...就像这样 - 虽然我通常会被告知更好的方式....: - )
创建一个名为work.txt
的文件,其中包含以下内容:
/media/video1.%(ext)s http://www.cnn.com/videos/us/2015/11/11/stun-gun-used-on-man-in-police-custody-dies-lawsuit-dnt-brown-tsr.cnn
/media/video2.%(ext)s http://www.cnn.com/videos/us/2015/11/11/5-year-old-saves-family-from-house-fire.ktla
然后命令是:
parallel --colsep " " youtube-dl -w --no-warnings -o {1} {2} < work.txt
另一种选择是简单地将两个命令放在一个文件中,并将其发送到GNU Parallel
的标准输入,如下所示:
将其存储在work.txt
youtube-dl -w --no-warnings -o "/media/video1.%(ext)s" "http://www.cnn.com/videos/us/2015/11/11/stun-gun-used-on-man-in-police-custody-dies-lawsuit-dnt-brown-tsr.cnn"
youtube-dl -w --no-warnings -o "/media/video2.%(ext)s" "http://www.cnn.com/videos/us/2015/11/11/5-year-old-saves-family-from-house-fire.ktla"
然后运行
parallel < work.txt