如何在TCL中使用spawn命令

发布于 2024-09-24 17:32:41 字数 637 浏览 5 评论 0原文

我在执行时使用以下代码

#!/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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

花桑 2024-10-01 17:32:41

在 package require Expect 之前删除“#”。

remove '#' before package require Expect.

何以畏孤独 2024-10-01 17:32:41

您遇到的问题是,当它在 Tcl 中运行时(我识别跟踪的格式),Expect 包(提供 spawn 命令)由于某种原因不存在。首先要做的是通过取消注释 package require 行来明确对 Expect 包的要求。这本身可能足以解决您的问题,但如果没有,它会抱怨软件包不可用。如果它不可用,则意味着它尚未安装,或者未找到它。前者……显然需要修复。 :-) 后者可以通过在 package require 之前添加一行类似的代码来解决:

lappend auto_path /full/path/to/Expect/package/installation

请注意,如果您使用 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 that package 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 that package require:

lappend auto_path /full/path/to/Expect/package/installation

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…

强者自强 2024-10-01 17:32:41

尝试在 tcl 解释器 (!/usr/bin/tcl) 下运行并导入 Expect。

Try running under tcl interpreter (!/usr/bin/tcl) and import Expect.

随心而道 2024-10-01 17:32:41

您的电脑上安装了 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

新一帅帅 2024-10-01 17:32:41
  1. sudo apt-get update -y
  2. sudo apt-get install -y Expect
  3. whichexpect

分别运行上述命令。如果安装正确,“whichexpect”将显示“/usr/bin/expect”作为输出。安装后运行脚本,

  1. sudo apt-get update -y
  2. sudo apt-get install -y expect
  3. which expect

Run the above commands respectively. If installed correctly, "which expect" will show "/usr/bin/expect" as an output. Run your script after installation,

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文