[英]Write ActiveState Tcl Program for Windows that expects a password and enters it
我想在 Windows 中編寫一個 shell 程序,該程序運行另一個 shell 腳本並期望來自 Git bash 終端的密碼提示並輸入它。 這是我到目前為止:
#!/bin/sh
# \
exec tclsh "$0" ${1+"$@"}
package require Expect
spawn sampleScript.sh
expect "Password:"
send "pass123"
sampleScript.sh 代碼:
echo 'Hello, world.' >foo.txt
我的程序輸出如下:
'The operation completed successfully. while executing "spawn sampleScript.sh"
(file "compare.tcl" line 6)'
但是,在腳本所在的本地文件夾中沒有創建 foo.txt。 你能幫我嗎?
期望程序的關鍵是讓生成的程序優雅地退出。 按照目前的情況,在您的期望腳本發送密碼后,它會立即退出,這會過早地殺死生成的程序。
如果您不需要與 sampleScript 交互(即讓它運行到完成),則期望腳本中的最后一行應該是
expect eof
否則,使用
interact
閱讀如何創建最小的、可重現的示例——您更新的代碼不會重現您看到的錯誤
send "password\\r"
expect eof
? 如果沒有,您可能會在它有機會創建輸出文件之前殺死 sampleScript.sh
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.