2015-11-13 57 views
1

我目前正在嘗試使用GNU Parallel,但是我沒有成功完成它。安裝非常簡單。我的目標是運行python腳本youtube-dl的兩個並行實例及其相應的參數。使用並行執行腳本的正確方法是什麼?執行多個腳本實例 - GNU並行

並行

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"' 

,如果運行命令seperately無並行工作:

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" 

回答

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並行......這樣的事情 - 雖然我就會告訴一個更好的辦法.... :-)

創建一個名爲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 
+0

大詳細回答。我能夠複製,現在它工作成功。 – MaryCoding