【问题标题】:Connect to streams additional to STDIN, STDOUT and STDERR from Java从 Java 连接到 STDIN、STDOUT 和 STDERR 以外的流
【发布时间】:2014-11-26 10:29:15
【问题描述】:

在由本地进程(Yate 电话引擎的 extmodule)通过 shell 脚本启动的 Java 进程中,可以连接到 STDIN 和 STDOUT 以与进程通信并将日志消息写入 STDERR。

Yate 的 extmodule 的描述中提到了两个额外的文件描述符 3 和 4:

The external user application or script comunicates with the module trough several file descriptors:

    0 (stdin) - Carries commands and notifications from engine to application
    1 (stdout) - Carries commands and answers from application to the engine
    2 (stderr) - Has the usual meaning of reporting errors and is directed to the engine's stderr or logfile
    3 (optional) - Transports audio data from the engine to the application
    4 (optional) - Transports audio data from the application to the engine 

File descriptors 3 and 4 are open only for audio capable applications. 

是否可以连接到那些可选的文件描述符,如果可以,如何连接?我知道我可以使用 System.inSystem.outSystem.err 来表示 0、1 和 2,但是其他的呢?

【问题讨论】:

    标签: java shell process


    【解决方案1】:

    如果 Yate 是另一个进程,并且您在 Unix / Linux / Mac OS 上运行(对于 Windows,它可能也可以工作,我只是不知道),您可以将 Yate 的文件描述符 3 和 4 重定向到管道和然后使用 Java 访问这些管道。

    如果您有 /proc 文件系统或类似的文件系统,也可以通过 /proc 文件系统访问文件。

    您说 java 是从 Yate 启动(即分叉)的。在这种情况下,另一种可能性是“黑客”FileDescriptor。目前FileDescriptor是一个只有三个实例的伪枚举,inouterr,分别对应012。 API 本身可以创建 FileDescriptor 的其他有效实例,但使用本机代码来执行此操作。我不知道如何通过普通的 Java API 打开一个由数字文件描述符已知的文件(这很难过,Oracle,你在听吗?!)。您可以编写自己的本机代码来执行此操作,但请注意,这基本上就像心脏直视手术。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多