【问题标题】:shell/dialog - Close dialog without user interactionshell/dialog - 在没有用户交互的情况下关闭对话框
【发布时间】:2023-02-23 05:39:05
【问题描述】:

简单地说,我在 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】:

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

    希望这对某人有帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-12
      • 1970-01-01
      相关资源
      最近更新 更多