我有一个 POE Perl 程序 fork 子项。
它所 fork 的子进程会进行日志记录和交互式远程登录到远程设备。 POE 使用 STDOUT 将输出返回到父进程,但由于某种原因它丢失了(不会显示到屏幕或任何文件)。
我推测这是因为 STDOUT 被重定向到某个地方 - 我需要确定在哪里。
我已使用 (-t STDOUT) 来识别子级的 STDOUT 不是 TTY。
在调用子级之前,我还将子级的 STDOUT 重置为父级的 STDOUT - 但此方法似乎避免了 POE 的事件处理程序,它只是将输出转储到父级 STDOUT。
问)如何识别当前 STDOUT 指向的内容,以便找到数据的去向
谢谢
西蒙
最佳答案
在这种情况下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.)
关于perl - 如何在 Perl 中找到进程 STDOUT 的当前值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1690270/