Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux expect:从stdin解析变量_Linux_Bash_Expect - Fatal编程技术网

Linux expect:从stdin解析变量

Linux expect:从stdin解析变量,linux,bash,expect,Linux,Bash,Expect,我正在运行一个expect脚本,该脚本将从stdin生成一些动态输入 是否有一种方法/模式可以解决从标准输入数据读取并将(?)存储在某个地方的概念,以便在后一步中处理/解析相关输入 示例: ./myexpectscript.sh arg1 arg2 .. Running command with id 9494 Running command with id 9494 Running command with id 9494 Running command with id 9494 Comma

我正在运行一个
expect
脚本,该脚本将从
stdin
生成一些动态输入

是否有一种方法/模式可以解决从标准输入数据读取并将(?)存储在某个地方的概念,以便在后一步中处理/解析相关输入

示例

./myexpectscript.sh arg1 arg2 ..

Running command with id 9494
Running command with id 9494
Running command with id 9494
Running command with id 9494
Command execution finished
我实际上想存储上面的id,
9494

该脚本实际上运行一个对远程服务器的api调用,持续时间为几秒钟(这很重要)

编辑:以下代码段似乎无法解决问题:

expect -re Running command with id [0-9]+

set output \$expect_out(1,string)
因为它给了我一个错误:

invalid command name "0-9"
    while executing
"0-9"
    invoked from within
"expect -re Running command with id [0-9]+"
    (file "./myexpectscript.sh" line 17)
我也用引号试过了,比如

expect -re "Running command with id [0-9]+"

使用
{…}
定义正则表达式,使用
\d
表示十进制数,并使用
(…)
捕获字符串

使用捕获的字符串
$expect\u out
设置变量

expect -re {Running command with id (\d+)} {
    set cmd_id $expect_out(1,string)
}
puts $cmd_id

使用
{…}
定义正则表达式,使用
\d
表示十进制数,并使用
(…)
捕获字符串

使用捕获的字符串
$expect\u out
设置变量

expect -re {Running command with id (\d+)} {
    set cmd_id $expect_out(1,string)
}
puts $cmd_id

非常感谢。。。这似乎是在做这项工作……有没有办法将变量存储在脚本之外的某个地方?以下内容:
VAR=$(./myexpectscript.sh arg1 arg2)
不起作用。如果在expect脚本中使用
put
,则在执行
$(./myexpectscript…
时应该能够获取字符串。您是否收到任何错误或空字符串?我已通过禁用所有其他输出
log\u用户0
,并使用
puts
,成功解决了此问题。非常感谢。。。这似乎是在做这项工作……有没有办法将变量存储在脚本之外的某个地方?以下内容:
VAR=$(./myexpectscript.sh arg1 arg2)
不起作用。如果在expect脚本中使用
put
,则在执行
$(./myexpectscript…
时应该能够获取字符串。您是否收到任何错误或空字符串?我已设法通过禁用所有其他输出
log\u用户0
并使用
put
来解决此问题,是的。