gpt4 book ai didi

linux - 如何避免与发送到派生进程的数据匹配

转载 作者:太空宇宙 更新时间:2023-11-04 09:53:56 24 4
gpt4 key购买 nike

在我期望的脚本中,下面的代码示例给我带来了很多麻烦

#!/usr/bin/expect
#some other code
set psucommand "psu |grep -v grep | grep $jobname\r"
#some other code
expect "env[lindex $argv 0]>" {send $psucommand}
expect {
"$jobname" {
send_user "$jobname"
send "exit\r"}
"env[lindex $argv 0]>" {
send_user ""
send "exit\r"}
}

第二个“预期”正在尝试(成功)匹配我发送到派生进程的实际 $psucommand (psu |grep -v grep | grep ACTUALJOBNAME\r),我只需要匹配派生进程的输出.

这是我用 expect -d 运行此脚本时接近尾声时看到的内容

expect: does " psu |grep -v grep | grep ACTUALJOBNAME\r\n" (spawn_id exp6) match glob pattern "ACTUALJOBNAME"? yes

它与我发送到派生进程的命令相匹配。我需要避免这种情况。

帮助!

最佳答案

set psucommand [format {psu | grep [%s]%s} \
[string index $jobname 0] \
[string range $jobname 1 end]]

这导致 psucommand 成为 psu | grep [A]CTUALJOBNAME

因此,您需要发送“$psucommand\r”,但期望 $jobname 不应接收命令。

关于linux - 如何避免与发送到派生进程的数据匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7795772/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com