如何在 Perl 中找到进程 STDOUT 的当前值?

发布于 2024-08-10 12:27:15 字数 367 浏览 7 评论 0原文

我有一个 POE Perl 程序分叉子项。

它所分叉的子进程会进行日志记录和交互式远程登录到远程设备。 POE 使用 STDOUT 将输出返回到父进程,但由于某种原因它会丢失(不会显示到屏幕或任何文件)。

我推测这是因为 STDOUT 被重定向到某个地方 - 我需要确定在哪里。

我已经使用 (-t STDOUT) 来识别孩子的 STDOUT 不是 TTY。

我还在调用子级之前将子级的 STDOUT 重置为父级的 STDOUT - 但此方法似乎避免了 POE 的事件处理程序,它只是将输出转储到父级 STDOUT。

问)如何识别当前 STDOUT 指向的内容,以便我可以找到我的数据的去向

谢谢

Simon

I have a POE Perl program forking children.

The children it is forking do logging and interactive telnets into remote devices.
POE uses STDOUT to return output back up to the parent process but for some reason it's getting lost (not going to screen or to any files).

I'm theorising that this is because STDOUT is being redirected somewhere - I need to ascertain where.

I have used (-t STDOUT) to identify that the STDOUT of the child is not a TTY.

I have also reset the STDOUT of the child to be that of the parent before the child was called - but this method seems to avoid POE's event handlers and it just dumps the output to parents STDOUT.

Q) How do I identify what the current STDOUT points at so I can find where my data is going

Thanks

Simon

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

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

发布评论

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

评论(4

感性 2024-08-17 12:27:15

fileno 在这种情况下会有帮助吗?如果子进程关闭并重新打开 STDOUT,则子进程中的 fileno(STDOUT) 值将与父进程中的值不同。

$ perldoc -f fileno
   fileno FILEHANDLE
           Returns the file descriptor for a filehandle, or undefined if
           the filehandle is not open.  This is mainly useful for
           constructing bitmaps for "select" and low-level POSIX tty-
           handling operations.  If FILEHANDLE is an expression, the value
           is taken as an indirect filehandle, generally its name.

           You can use this to find out whether two handles refer to the
           same underlying descriptor:

               if (fileno(THIS) == fileno(THAT)) {
                   print "THIS and THAT are dups\n";
               }

           (Filehandles connected to memory objects via new features of
           "open" may return undefined even though they are open.)

Would fileno help in this situation? If a child is closing and reopening STDOUT, then fileno(STDOUT) would have a different value in the child than in the parent.

$ perldoc -f fileno
   fileno FILEHANDLE
           Returns the file descriptor for a filehandle, or undefined if
           the filehandle is not open.  This is mainly useful for
           constructing bitmaps for "select" and low-level POSIX tty-
           handling operations.  If FILEHANDLE is an expression, the value
           is taken as an indirect filehandle, generally its name.

           You can use this to find out whether two handles refer to the
           same underlying descriptor:

               if (fileno(THIS) == fileno(THAT)) {
                   print "THIS and THAT are dups\n";
               }

           (Filehandles connected to memory objects via new features of
           "open" may return undefined even though they are open.)
月牙弯弯 2024-08-17 12:27:15

如果您的分叉子项也是 Perl 程序,您可以“选择 STDOUT”并设置 $|在任何日志记录发生之前将其标记为未缓冲。

If your forked children are Perl programs too you can "select STDOUT" and set $| to mark it unbuffered right before any logging happens.

久夏青 2024-08-17 12:27:15

这是由于子进程发送的 POE::Filter::Reference StdOut Handler 的输出格式不符合其预期。

删除过滤器 - 然后可以看到它正在发送的内容,这使我能够纠正问题。

问题是子进程将其子进程 STDOUT 的内容沿着套接字连接喷回到 StdOut 处理程序。

西蒙

This was down to the POE::Filter::Reference StdOut Handler being sent output by the child process that was not in the format it was expecting.

Removed the filter - could then see what it was being sent and this enabled me to rectify the issue.

The issue was the child process was spewing the contents of its subprocesses STDOUT back along the socket connection to the StdOut Handler.

Simon

燃情 2024-08-17 12:27:15

您确定这不是缓冲问题吗?我不熟悉 POE,所以我不知道你会如何调查或纠正它,但我怀疑至少值得检查。

Are you certain this isn't a buffering issue? I'm not familiar with POE so I don't know how you'd investigate or correct that, but I suspect it's worth checking, at least.

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