Scripting 期望:如何使用;ls-d文件名“;对于expect中的完整路径名?
我正在尝试使用expect在硬件上自动加载图像。为此,我需要得到图像的完整路径 我使用以下语法-Scripting 期望:如何使用;ls-d文件名“;对于expect中的完整路径名?,scripting,automation,expect,Scripting,Automation,Expect,我正在尝试使用expect在硬件上自动加载图像。为此,我需要得到图像的完整路径 我使用以下语法- spawn ls -d $env(PWD)/build/image/bmxs.*bin expect -re {(\S+)(\r)} set imgpath $expect_out(1,string) 我得到的信息是- spawn: returns {51875} expect: does "" (spawn_id exp4) match regular expression "(\S+)(\r
spawn ls -d $env(PWD)/build/image/bmxs.*bin
expect -re {(\S+)(\r)}
set imgpath $expect_out(1,string)
我得到的信息是-
spawn: returns {51875}
expect: does "" (spawn_id exp4) match regular expression "(\S+)(\r)"? no
因此,似乎繁殖不会返回任何内容
我尝试过各种语法,但没有用-
send "ls -d $env(PWD)/build/images/final/nxos.*bin\r"
spawn "ls -d $env(PWD)/build/image/bmxs.*bin"
puts "$LS" ### where $LS is the command.
这些都不管用。我犯了错误吗?您的代码表明
set files [glob $env(PWD)/build/image/bmxs.*bin]
set imgpath [lindex [lsort $files] 0]
另一方面,短语“在硬件上”表示此映像文件位于某个远程系统上。如果是这样,并且您已经在那里生成了一个登录会话,那么您需要在现有会话上发送ls
命令,然后期望ls
的输出。但是,在这种情况下,从$env(PWD)”获取目录看起来很奇怪,因为这将读取本地计算机上的环境变量PWD