如何在TCL中使用spawn命令
我在执行时使用以下代码
#!/usr/bin/expect -f
#!usr/bin/expect
#package require Expect
puts "Hello world"
spawn ssh [email protected]
expect -nocase "password:"
send "abc123\r"
puts "done"
,它抛出错误
Hello world
invalid command name "spawn"
while executing
"spawn ssh [email protected]"
(file "temp.tcl" line 9)
我的代码出了什么问题
I am using the following code
#!/usr/bin/expect -f
#!usr/bin/expect
#package require Expect
puts "Hello world"
spawn ssh [email protected]
expect -nocase "password:"
send "abc123\r"
puts "done"
while executing, it throws error
Hello world
invalid command name "spawn"
while executing
"spawn ssh [email protected]"
(file "temp.tcl" line 9)
whats the wrong in my code
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在 package require Expect 之前删除“#”。
remove '#' before package require Expect.
您遇到的问题是,当它在 Tcl 中运行时(我识别跟踪的格式),Expect 包(提供
spawn
命令)由于某种原因不存在。首先要做的是通过取消注释package require
行来明确对 Expect 包的要求。这本身可能足以解决您的问题,但如果没有,它会抱怨软件包不可用。如果它不可用,则意味着它尚未安装,或者未找到它。前者……显然需要修复。 :-) 后者可以通过在package require
之前添加一行类似的代码来解决:请注意,如果您使用 expect 程序而不是 tclsh 运行脚本 程序,
package require
将会自动为您完成。显然你没有这样做……The problem you've got is that while it is running in Tcl (I recognize that format of trace), the Expect package (which provides the
spawn
command) is absent for some reason. The first thing to do is to make the requirement for the Expect package explicit by uncommenting thatpackage require
line. That may be enough to fix your problem in itself, but if not it will complain about the package not being available. If it's not available, that means either that it just isn't installed, or that it's not being found. The former is... obvious to fix. :-) The latter is resolved by putting a line like this before thatpackage require
:Note that if you run the script with the expect program instead of the tclsh program, that
package require
will be done for you automatically. You're obviously not doing that…尝试在 tcl 解释器 (!/usr/bin/tcl) 下运行并导入 Expect。
Try running under tcl interpreter (!/usr/bin/tcl) and import Expect.
您的电脑上安装了 Expect 吗?
请在您的电脑上运行以下命令来检查 Expect 是否可用。
$which 期望
/usr/bin/expect
Did you installed Expect on your PC?
Please run the following command on your PC to check if Expect is available.
$which expect
/usr/bin/expect
分别运行上述命令。如果安装正确,“whichexpect”将显示“/usr/bin/expect”作为输出。安装后运行脚本,
Run the above commands respectively. If installed correctly, "which expect" will show "/usr/bin/expect" as an output. Run your script after installation,