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

发布于 2024-12-10 12:15:50 字数 706 浏览 0 评论 0原文

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

#!/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

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

帮助!

In my expect script following code sample is making me a lot of troubles

#!/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"}
}

This second "expect" is trying (successfully) to match the actual $psucommand (psu |grep -v grep | grep ACTUALJOBNAME\r) I send to the spawned process, and I need only the spawned process's output to be matched.

Here's what I see near the end when I run this script with expect -d

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

It's matching my command I sent to the spawned process. I need to avoid this.

Help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

ㄖ落Θ余辉 2024-12-17 12:15:51
set psucommand [format {psu | grep [%s]%s} \
                   [string index $jobname 0] \
                   [string range $jobname 1 end]]

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

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

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

This results in psucommand being psu | grep [A]CTUALJOBNAME

So, you need to send "$psucommand\r" but expecting on $jobname should not pickup the command.

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