簡體   English   中英

從Java連接到STDIN,STDOUT和STDERR之外的流

[英]Connect to streams additional to STDIN, STDOUT and STDERR from Java

在由本地進程(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,但是其他的呢?

如果Yate是另一個進程,並且您正在Unix / Linux / Mac OS上運行(對於Windows,它也可能工作,我只是不知道),則可以將Yate的文件描述符3和4重定向到管道,然后使用Java訪問這些管道。

它可能也行,如果你有一個/proc文件系統或類似的東西,通過訪問文件/proc文件系統。

您說Java是從Yate啟動(即分叉的)。 在這種情況下,另一種可能性是“入侵” FileDescriptor 目前, FileDescriptor是偽枚舉只有三個實例, inout ,並err ,對應於012分別。 API本身可以創建FileDescriptor的其他有效實例,但可以使用本機代碼來創建。 我不知道通過普通Java API打開數字文件描述符所知文件的方法(可悲的是,Oracle,您在聽嗎?!)。 您可以編寫自己的本機代碼來執行此操作,但是請注意,這基本上就像是心臟直視手術。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM