値を入力した後、スクリプトが続くと予想されます。

値を入力した後、スクリプトが続くと予想されます。

私は次のような予想されるスクリプトを書いた。

#!/usr/bin/expect -f
set timeout 10
spawn zypper in --no-recommends pdns
expect {
  -re {^.* Solution (\d): (?:break pdns)} {
    set solution "$expect_out(1,string)"
    exp_continue
  }
  "Choose from above solutions by number or cancel" {
   puts "$solution"
   send "\r"
  }
}

プログラムは$solution私の場所を正しく配置しましたが(以下の例では「3」が正しく配置されています)、実行を中断してキャリッジリターンを送信しているように見えますが、生成中のzypperコマンドが続行することはできません。

suse-test-647578bd8-95qsc:/ # ./install-pdns.expect 
spawn zypper in --no-recommends pdns
Refreshing service 'container-suseconnect-zypp'.
Problem retrieving the repository index file for service 'container-suseconnect-zypp':
[container-suseconnect-zypp|file:/usr/lib/zypp/plugins/services/container-suseconnect-zypp] 
Warning: Skipping service 'container-suseconnect-zypp' because of the above error.
Loading repository data...
Reading installed packages...
Resolving package dependencies...

Problem: the to be installed pdns-4.6.2-lp154.186.32.x86_64 requires 'systemd', but this requirement cannot be provided
  not installable providers: systemd-249.11-150400.6.8.x86_64[SLE_BCI]
 Solution 1: Following actions will be done:
  remove lock to allow installation of systemd-249.11-150400.6.8.x86_64[SLE_BCI]
  remove lock to allow installation of systemd-default-settings-branding-SLE-0.7-3.2.1.noarch[SLE_BCI]
  remove lock to allow installation of systemd-presets-branding-SLE-15.1-20.8.1.noarch[SLE_BCI]
  remove lock to allow installation of systemd-default-settings-0.7-3.2.1.noarch[SLE_BCI]
  remove lock to allow installation of systemd-presets-common-SUSE-15-150100.8.12.1.noarch[SLE_BCI]
 Solution 2: do not install pdns-4.6.2-lp154.186.32.x86_64
 Solution 3: break pdns-4.6.2-lp154.186.32.x86_64 by ignoring some of its dependencies

Choose from above solutions by number or cancel [1/2/3/c/d/?] (c): 3

suse-test-647578bd8-95qsc:/ #

区切りとputsto をsend結合しようとしましたが、puts "$solution\r"値を入力せずに中断されます。

追加してみました

eof { exp_continue }
"Installing:" { exp_continue }
eof {}

隣人に興味を持ち、既存の隣人をexpect見てみてください。どちらも注文が進んでいるようではありません。eofexpectzypper

明確にするには:手動で実行するにはzypper「3」が必要です。「Enter」を押してからパッケージのインストールを続けます(したがって、「インストール:」を待ってください)。

試してみる他のことについて提案をいただきありがとうございます!

読んでくれてありがとう!

ベストアンサー1

@meuthの提案を使用して、次の操作を行いますexp_continue

#!/usr/bin/expect -f
set timeout 10
spawn zypper in --no-recommends pdns
expect {
  -re {^.* Solution (\d): (?:break pdns)} {
    set solution "$expect_out(1,string)"
    exp_continue
  }
  "Choose from above solutions by number or cancel" {
   send "$solution\r"
   exp_continue
  }
  eof {}
}

おすすめ記事