我在expect文件中写了一些代码:
#!./expect -f
set timeout -1
spawn /path/to/command --foo param1 --bar param2 --password
expect "Password for baz which is prompted on the console.: "
send "pass\r"
expect "> "
send "print\r"
expect "> "
send -- "\r"
当我运行它时,输出是:
spawn /path/to/command --foo param1 --bar param2 --password
Password for baz which is prompted on the console.:
> print
{"stuff"}
>
>
我在bash的这里doc中有一些代码:
variable=$(/usr/bin/expect <<HEREKALpxT5KZu
set timeout -1
spawn /path/to/command --foo param1 --bar param2 --password
expect "Password for baz which is prompted on the console.: "
send "pass\r"
expect "> "
send "print\r"
expect "> "
send -- "\r"
HEREKALpxT5KZu
)
我希望这段代码能够生成与运行expect文件完全相同的输出,但是打印变量时的输出是:
spawn /path/to/command --foo param1 --bar param2 --password
Password for baz which is prompted on the console.:
>
没有第二个“&gt;”而且没有{“stuff”}。就像打印命令永远不会发送一样。另外,当我在最后添加“interact”时,它只适用于expect文件,而不适用于此文档。