如何使用选项设置期望脚本

How to set an expect script with options

我正在使用 expect 在 TCP 服务器停止工作时重新启动它。服务器本身有多个我可以设置的参数(它是一个 python 代码)。

#!/usr/bin/expect
set timeout -1

spawn python2.7 -u gfsk_rx.py -d "rtl_sdr=0" -s 1000000 -f 437500000 -b 9600 -w 25000 -g 1 -o "/dev/null" -i "127.0.0.1" -p 7000 

expect "Press Enter to quit: file_descriptor_sink"
send -- 'r'

如您所见,我可以在 python 代码中设置多个参数(-d、-s、-f 等)。

我想知道我是否也可以通过

之类的方式 运行 我的期望代码
while true; do expect my_script.exp --device "uhd=0"; done

这会将我的 -d "rtl_sdr=0" 更改为 "uhd=0"

我试过使用“$1”、“$2”等,但没有用。我想知道是否可以这样做,但我找不到解决方案。

此问题包含与您正在做的事情相关的有用信息:how to write a tcl procedure with default values and options?

命令行参数可以在全局 $argv 列表中找到。您可以遍历该列表,测试值。 This chapter of the Tcl tutorial 提供了更多细节。

cmdline package from tcllib 也可能对您有用。