![](/img/trans.png)
[英]How to simulate just one ENTER in command line after executing a JAR file
[英]simulate enter keypress after a command is executed
我正在對主機執行SSH並執行命令,該命令要求您按Enter鍵。 (它兩次詢問不同的事物。)
我在這里使用生成期望。
發送報告命令時,它將要求您按ENTER鍵。 完成后,再次要求您按Enter鍵。 我想自動發送回車鍵。
#!/usr/bin/expect
spawn ssh user@host report
expect "Press ENTER to continue, or CTRL-C to quit."
send " \r"
expect "Press enter for inputing"
send "\r"
ENTER應該自動完成,並獲得命令的最終結果。
說您在機器“ audrey”上具有“ report”腳本:
#!/bin/bash
echo -n "Press ENTER to continue, or CTRL-C to quit."
read
echo -n "Press enter for inputing"
read
read s
echo "You sent: $s"
和本地的期望腳本:
#!/usr/bin/expect
spawn ssh audrey ./report
expect "Press ENTER to continue, or CTRL-C to quit."
send "\n"
expect "Press enter for inputing"
send "\n"
send "OK\n"
expect "You sent: OK"
close
./a。期望輸出:
spawn ssh audrey ./report
Press ENTER to continue, or CTRL-C to quit.
Press enter for inputing
OK
You sent: OK
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.