![](/img/trans.png)
[英]Starting a process with inherited stdin/stdout/stderr in Java 6
[英]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.in
, System.out
和System.err
用于0、1和2,但是其他的呢?
如果Yate是另一个进程,并且您正在Unix / Linux / Mac OS上运行(对于Windows,它也可能工作,我只是不知道),则可以将Yate的文件描述符3和4重定向到管道,然后使用Java访问这些管道。
它可能也行,如果你有一个/proc
文件系统或类似的东西,通过访问文件/proc
文件系统。
您说Java是从Yate启动(即分叉的)。 在这种情况下,另一种可能性是“入侵” FileDescriptor
。 目前, FileDescriptor
是伪枚举只有三个实例, in
, out
,并err
,对应于0
, 1
和2
分别。 API本身可以创建FileDescriptor的其他有效实例,但可以使用本机代码来创建。 我不知道通过普通Java API打开数字文件描述符所知文件的方法(可悲的是,Oracle,您在听吗?!)。 您可以编写自己的本机代码来执行此操作,但是请注意,这基本上就像是心脏直视手术。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.