如何在 Perl 中找到进程 STDOUT 的当前值?
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
fileno
在这种情况下会有帮助吗?如果子进程关闭并重新打开STDOUT
,则子进程中的fileno(STDOUT)
值将与父进程中的值不同。Would
fileno
help in this situation? If a child is closing and reopeningSTDOUT
, thenfileno(STDOUT)
would have a different value in the child than in the parent.如果您的分叉子项也是 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.
这是由于子进程发送的 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
您确定这不是缓冲问题吗?我不熟悉 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.