YAD結果をファイルにリダイレクトし、ボタンからSTDOUTへの終了コードを提供し続けます。

YAD結果をファイルにリダイレクトし、ボタンからSTDOUTへの終了コードを提供し続けます。

私のyad --formには2つのカスタムボタンがあります。ユーザー入力(別名結果)は、後で使用するために.txtファイルにリダイレクトされます。それはうまくいきます。

ところで、このようにリダイレクトすると、終了コードはもはやSTDOUTに提供されないようです。しかし、もちろん、進行方法を決定するには終了コードが必要です。

私は正しい道を行っていますか?終了コードをSTDOUTに渡す別の解決策はありますか?

yad --title="egPorSS - TYPO3 Constants Setup" --center --borders="20" --width="500" --separator="\n" 2> /dev/null \
        --form \
        --field="egON API-Key":TEXT \
        --field="Host for AJAX-Requests":TEXT \
        --field="SOAP-Username":TEXT \
        --field="SOAP-Password":TEXT \
        --field="SOAP-URL:":TEXT \
        --field="SEPA-Service":CHK \
        --field="Base-Provider":CHK \
        --field="Digital Signature":CHK \
        --field="Company name":TEXT \
        --field="Street, Number":TEXT \
        --field="City":TEXT \ 
        --button="Discard entries":1 \
        --button="Write to DB":0 > ./temp/constants_modified.txt # Write entries to .txt file.

# if Button "Write to DB" is pressed, ask again, before manipulating DB
if [ $? -eq 0 ]; then
        yad --title="egPorSS - TYPO3 Constants Setup" --center --borders="20" 2> /dev/null \
            --text="Write changes to constants field in ${DB} now?" \
            --button="No, discard":0 \
            --button="Yes, write":1 
        # if "Yes, write" => modify ./temp/constants_${DB}.typoscript" and coll pushConstantsDB()
        if [ $? -eq 1 ]; then
            sed -i "s/plugin.tx_egon_pi1.system.apiKey.*/plugin.tx_egon_pi1.system.apiKey = ${modified[0]}/" ${typoscript}
            sed -i "s/plugin.tx_egon_pi1.system.host.*/plugin.tx_egon_pi1.system.host = ${modified[1]}/" ${typoscript}
            sed -i "s/plugin.tx_egon_pi1.soap.user.*/plugin.tx_egon_pi1.soap.user = ${modified[2]}/" ${typoscript}
            sed -i "s/plugin.tx_egon_pi1.soap.password.*/plugin.tx_egon_pi1.soap.password = ${modified[3]}/" ${typoscript}
            sed -i "s/plugin.tx_egon_pi1.soap.url.*/plugin.tx_egon_pi1.soap.url = ${modified[4]}/" ${typoscript}
            sed -i "s/plugin.tx_egon_pi1.settings.useSEPA.*/plugin.tx_egon_pi1.settings.useSEPA = ${modified[5]}/" ${typoscript}
            sed -i "s/plugin.tx_egon_pi1.settings.useBaseProvider.*/plugin.tx_egon_pi1.settings.useBaseProvider = ${modified[6]}/" ${typoscript}
            sed -i "s/plugin.tx_egon_pi1.settings.signatureAllowed.*/plugin.tx_egon_pi1.settings.signatureAllowed = ${modified[7]}/" ${typoscript}
            sed -i "s/plugin.tx_egon_pi1.custom.companyName.*/plugin.tx_egon_pi1.custom.companyName = ${modified[8]}/" ${typoscript}
            sed -i "s/plugin.tx_egon_pi1.custom.companyStreet.*/plugin.tx_egon_pi1.custom.companyStreet = ${modified[9]}/" ${typoscript}
            sed -i "s/plugin.tx_egon_pi1.custom.companyCity.*/plugin.tx_egon_pi1.custom.companyCity = ${modified[10]}/" ${typoscript}
            echo -e "${LIBLUE}Writing changes to Database now.. ${NF}\n"
            pushConstantsDB
        else
            echo -e "${LIBLUE}Returning to main menu without any changes.. ${NF}"
            sleep 6     
        fi
    else
        echo -e "${LIBLUE}Returning to main menu without any changes.. ${NF}"
        sleep 6
    fi

ベストアンサー1

私はこれが古い質問であることを知っていますが、誰も答えなかったし、解決策は本当に簡単です。

OPはYADの結果と終了コードを要求しました。私の理解が正しい場合は、結果をYADの変数として表示する必要があり(配列が簡単になります)、終了コードが戻りコードを意味すると仮定します。戻りコードはどのボタンが押されたかを示しますが、OP投稿にはフォームに入力されたデータを収集する内容はありません。

実行する必要があるのは、ユーザーが「データベースに書き込む」ボタンをクリックすると、データはフォームに保存されますが、確認を要求する2番目のダイアログボックスが表示されることです。これは新しいデータを表示したり表示したりすることなく行うことができますが、検査のために再表示するのは合理的です。これが私の解決策です。

#!/bin/bash
input=$(yad --title="egPorSS - TYPO3 Constants Setup" --center --borders="20" --width="500" --separator="\n" 2> /dev/null \
        --form \
        --field="egON API-Key":TEXT \
        --field="Host for AJAX-Requests":TEXT \
        --field="SOAP-Username":TEXT \
        --field="SOAP-Password":H \
        --field="SOAP-URL:":TEXT \
        --field="SEPA-Service":CHK \
        --field="Base-Provider":CHK \
        --field="Digital Signature":CHK \
        --field="Company name":TEXT \
        --field="Street, Number":TEXT \
        --field="City":TEXT \
        --button="gtk-cancel:1" \
        --button=" Update DB!iconok.png:2"  \
2>/dev/null
);return_code=$?

[[ "$return_code" -eq "2" ]] && { printf '%s\n' "${input[@]}"| yad --text-info --width="400" --height="400" --title="New Data" \
        --button="gtk-cancel:1" \
        --button=" Update DB!iconok.png:2" \
2>/dev/null
};return_code=$?
# See if "Update DB" was clicked
[[ "$return_code" -eq "2" ]] && echo "Update DB was clicked" || echo "Cancel was clicked"

yadダイアログボックスには必要なデータフィールドが表示され、出力は入力と呼ばれる配列に保存されます。戻りコードは、押したキーの値を保持します。この場合、「1」は「キャンセル」をクリックしたことを意味し、「2」は「データベース更新」を意味する。データをフォームに再表示し、入力された値を事前入力し、確認を要求するように操作できる簡単なチェックを追加しました。確認されたら、「入力」配列のデータを処理できます。 OPがスクリプトの2番目の部分で何をしているのかわかりません。

私が追加した追加:

  • セキュリティのために、SOAPパスワードフィールドに入力したデータは非表示になります。
  • 「データベースの更新」ボタンに iconok.png という緑色の確認アイコンを追加しました。これにより、「キャンセル」ボタンの横にあるスペースよりも見やすくなります。次のようになります。

ヤーデ形式

入力されたデータを示す2番目の画面です。ただし、必要に応じて処理できます。

YADテーブルのデータ

おすすめ記事