运行expect时标准输出没有结果

发布于 2024-09-25 05:22:37 字数 170 浏览 3 评论 0原文

每当我尝试运行该脚本时,它都不会在标准输出上显示任何结果。

#!/usr/bin/expect --
send [exec tail -f /var/opt/jboss/log/jbossall.log | grep -i "pattern"]

请告知原因。

Whenever I try to run the script it doesn't show me any result on standard output.

#!/usr/bin/expect --
send [exec tail -f /var/opt/jboss/log/jbossall.log | grep -i "pattern"]

Please advise the reason.

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

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

发布评论

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

评论(1

风吹短裙飘 2024-10-02 05:22:37

exec 命令永远不会完成,因为您使用的是 tail -f。从 tail 的信息页面:“永远循环尝试在文件末尾读取更多字符”。由于 exec 未完成,因此永远不会调用 send

你可能需要做这样的事情:

spawn whatever
set whatever_id $spawn_id

spawn sh -c {tail -f /var/opt/jboss/log/jbossall.log | grep -i "pattern"}
set tail_id $spawn_id

while {1} {
    expect -i $tail_id "(.*)\n"
    send -i $whatever_id $expect_out(1,string)
}

The exec command never completes because you're using tail -f. From the info page for tail: "Loop forever trying to read more characters at the end of the file". Since exec does not complete, send is never invoked.

You probably need to do something like this:

spawn whatever
set whatever_id $spawn_id

spawn sh -c {tail -f /var/opt/jboss/log/jbossall.log | grep -i "pattern"}
set tail_id $spawn_id

while {1} {
    expect -i $tail_id "(.*)\n"
    send -i $whatever_id $expect_out(1,string)
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文