Shell Unix Expect:将命令的输出捕获为Expect变量

Shell Unix Expect:将命令的输出捕获为Expect变量,shell,variables,unix,tcl,expect,Shell,Variables,Unix,Tcl,Expect,我试图在unix中捕获程序的输出,并将其用作expect脚本中的变量。当我执行该程序时,我会得到如下结果: [user@svr]# ./passwdgenerator 1234*&^^[user@svr]# 如您所见,“1234*&^^^”是我想要捕获并将其放入expect脚本中的密码: set user user1 set password [open ./passwdgenerator] spawn ssh $user@server1.com expect "password:"

我试图在unix中捕获程序的输出,并将其用作expect脚本中的变量。当我执行该程序时,我会得到如下结果:

[user@svr]# ./passwdgenerator
1234*&^^[user@svr]# 
如您所见,“1234*&^^^”是我想要捕获并将其放入expect脚本中的密码:

set user user1
set password [open ./passwdgenerator]
spawn ssh $user@server1.com
expect "password:"
send "$password\r"
显然,它目前不起作用,只是想知道我应该如何写这个。以前在txt文件上尝试过这个,成功了。但当它是一个程序输出时,出于安全原因,我们不想在文本文件中存储密码,所以它不起作用。有专家能帮我吗?非常感谢

这条线

set password [open ./passwdgenerator]
改为

set password [exec ./passwdgenerator]
这条线

set password [open ./passwdgenerator]
改为

set password [exec ./passwdgenerator]
尝试
发送“$password”
或(可能)
发送“$password\n”
尝试
发送“$password”
或(可能)
发送“$password\n”