簡體   English   中英

bash無法從aria2c捕獲到變量和stdout的輸出

[英]bash can't capture output from aria2c to variable and stdout

我正在嘗試使用aria2c下載文件。 該命令如下所示:

aria2c --http-user=$USER --http-passwd=$usepw -x 16 -s 100 $urlPath

以這種方式運行時,該命令在腳本中可以完美運行。 我想要做的是將命令的輸出捕獲到變量中,並仍將其實時顯示在屏幕上。

我已成功使用以下命令將輸出捕獲到變量中:

VAR=$(aria2c --http-user=$USER --http-passwd=$usepw -x 16 -s 100 $urlPath)

但是,在這種情況下,屏幕上會存在很長的延遲,在進行下載的過程中沒有更新。 我在腳本中的這一行之后有一個echo命令,並且$ VAR具有捕獲的所有aria2c下載數據。

我嘗試使用2>&1和|的不同組合。 在命令末尾使用tee / dev / tty,但實時顯示中沒有任何顯示。

Example:
VAR=$(aria2c --http-user=$USER --http-passwd=$usepw -x 16 -s 100 $urlPath 2>&1)
VAR=$(aria2c --http-user=$USER --http-passwd=$usepw -x 16 -s 100 $urlPath 2>&1 | tee /dev/tty )
VAR=$(aria2c --http-user=$USER --http-passwd=$usepw -x 16 -s 100 $urlPath | tee /dev/tty )
VAR=$((aria2c --http-user=$USER --http-passwd=$usepw -x 16 -s 100 $urlPath) 2>&1)
VAR=$((aria2c --http-user=$USER --http-passwd=$usepw -x 16 -s 100 $urlPath) 2>&1 | tee /dev/tty )
VAR=$((aria2c --http-user=$USER --http-passwd=$usepw -x 16 -s 100 $urlPath) 2>&1 ) | tee /dev/tty )

我已經可以在其他命令中使用“ 2>&1 | tee”組合,但是由於某種原因,我似乎無法同時捕獲aria2c和這兩個命令。 有人從bash腳本中做到這一點嗎?

由於aria2c似乎輸出到標准輸出,考慮tee荷蘭國際集團,為標准錯誤:

var=$(aria2c --http-user=$USER --http-passwd=$usepw -x 16 -s 100 $urlPath | tee /dev/fd/2)

stdout以var結尾,而tee將其復制到stderr,stderr將顯示在屏幕上。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM