shell/dialog - 无需用户交互即可关闭对话框

问题描述 投票:0回答:1

简单地说,我在 BASH 中使用 Dialog 来生成消息并有一个交互式菜单。不过,作为一步,我需要等待用户插入硬件设备,所以我运行了一个带有回显功能的“tailbox”。

现在我只是回显“请退出对话框”,但为了简化目的,我想自己关闭对话框。我已经添加了一个超时时间,但这是为了确保用户不会卡在那个屏幕上,所以它很长。

有没有办法让它在脚本结束时对话框休眠 2-3 秒然后关闭?

非常感谢任何帮助!

function initRPI { # Wait for carrier Board to be plugged in, then initialize CM Unit
    echo -e "Plug in carrier board with compute module attached.\n"
    pkill "rpiboot"
    sleep 0.5
    $FILE # Run rpiboot from where it's installed
    echo -e "\nCompute Module Initialized - Exit Now."
}

function writeImage { # Find proper image and write it to device
    if [[ " ${boxTypes[*]} " =~ "$boxType" ]]; then
        initRPI > _temp &
        dialog --backtitle "$backTitle" --fb --title "Image Writer" --timeout 60 --tailbox _temp 15 70
        if pgrep -f rpiboot &> /dev/null 2>&1; then
            pkill "rpiboot"
            dialogMsg FAILED "Compute Module was not initialized."
        else
            devCM="/dev/sda"
            if [ ! -d "/mnt/firmware" ]; then
                mkdir /mnt/firmware
            fi
            mount -t nfs $nasIP/firmware /mnt/firmware
            (pv -n "/mnt/firmware/${unitSerial:2:4}.img" | dd of="$devCM" bs=4M conv=notrunc,noerror) 2>&1 | dialog --gauge "Running cloning $imageName to device $1, please wait..." 10 70 0
            sleep 0.5
            if kill -0 "$pid" ; then
                dialogMsg SUCCESS "Image $imageName written to device $1."
            else
                dialogMsg FAILED "Image $imageName failed to write to device $1."
            fi
        fi
    else
        dialogMsg ERROR "Can't find $boxType in the model list."
    fi
}

我让它分叉 rpiboot 进程,所以 tail 只读取一个临时变量,但我必须等待用户输入在 rpiboot 完成时退出。

编辑:我意识到我把 --timeout 放在了 --tailbox 参数中,所以很快就移动了它。

bash shell dialog fork interaction
1个回答
0
投票

我想通了。我基本上可以删除 EXIT 按钮并用 pkill "dialog" 强行关闭对话框窗口。

希望这对某人有帮助!

© www.soinside.com 2019 - 2024. All rights reserved.