inu*_*aze 5 bash download x11 wget
我正在尝试将此代码从wget + zenity
移植到wget + kdialog
.
代码zenity
:
#!/bin/bash
# Start wget | zenity
# Note the & at the end of the pipe, this allows the script to continue with wget running in the background
wget http://www.zezeniaonline.com/download/downloadlinux 2>&1 | sed -u 's/.* \([0-9]\+%\)\ \+\([0-9.]\+.\) \(.*\)/\1\n# Downloading at \2\/s, ETA \3/' | zenity --progress --title="Downloading File..."
#Start a loop testing if zenity is running, and if not kill wget
RUNNING=0
while [ $RUNNING -eq 0 ]
do
if [ -z "$(pidof zenity)" ]
then
pkill wget
RUNNING=1
fi
done
Run Code Online (Sandbox Code Playgroud)
Zenity 代码完美运行
我需要做同样的事情,但是使用kdialog
. 我首先尝试使用以下代码:
#!/bin/bash
# Start wget | kdialog
wget http://www.zezeniaonline.com/download/downloadlinux 2>&1 | sed -u 's/.* \([0-9]\+%\)\ \+\([0-9.]\+.\) \(.*\)/\1\n# Downloading at \2\/s, ETA \3/' | kdialog --progressbar " " --title="Downloading File..."
#Start a loop testing if zenity is running, and if not kill wget
RUNNING=0
while [ $RUNNING -eq 0 ]
do
if [ -z "$(pidof kdialog)" ]
then
pkill wget
RUNNING=1
fi
done
Run Code Online (Sandbox Code Playgroud)
根本不起作用
#!/bin/bash
# Start wget | kdialog
wget --progress=dot http://www.zezeniaonline.com/download/downloadlinux 2>&1 | fgrep --line-buffered '%' \ | sed -u -r 's:.* ([0-9]+)% .*:\1:' | kdialog --title "Installation" --progressbar " " &
#Start a loop testing if kdialog is running, and if not kill wget
RUNNING=0
while [ $RUNNING -eq 0 ]
do
if [ -z "$(pidof kdialog)" ]
then
pkill wget
RUNNING=1
fi
done
Run Code Online (Sandbox Code Playgroud)
但出现以下错误。 是的,它正在下载,但是“kdialog”中的“进度”不是“进度”
小智 2
这是我自己的解决方案,我在本页链接的网站上修改了一些旧教程:
这段代码将尝试下载我在 github 上的主存储库
link="https://github.com/nowardev/kde-peace-settings/archive/master.zip" #my own github stuff
a=$(kdialog --progressbar "W-Get will download: Nowardev GitHub Master stuff " 100);sleep 2
qdbus $a showCancelButton true
while read line ;do
read -r p t <<< "$line"
echo $p
echo $t
qdbus $a Set org.kde.kdialog.ProgressDialog value $p
while [[ $(qdbus $a wasCancelled) != "false" ]] ; do
echo "KILLING THE PROCESS AND KDIALOG"
qdbus $a org.kde.kdialog.ProgressDialog.close
exit
done
qdbus $a org.kde.kdialog.ProgressDialog.setLabelText "W-Get will download: Nowardev GitHub Master stuff time left : $t"
done< <(wget "$link" 2>&1 |mawk -W interactive '{ gsub(/\%/," "); print int($7)" "$9 }')
Run Code Online (Sandbox Code Playgroud)