开发者

Java ProcessBuilder how to capture file reading request from process and provide as stream?

I am somewhat familiar with ProcessBuilder and do process the streams. Now I ran into the problem that the process that I am automating reads some information from two files that I need to provide. Currently, I am writing the files and provide the paths to the program via ProcessBuilder. Since I am expecting to have millions of runs in the near future I would like to speed-up things by doing all work in memory and not reading and writing to file.

Basically, what I need to be able to do is capture the file open request from the automated program and provide the expected data from a stringstream or something similar. Of course if I could tell ProcessBuilder somehow that the file paths I am giving be replaced by streams that would be开发者_运维问答 even better.

How can I achieve this?


There is no interface to Process that allows you to intercept and modify I/O access like that. Unless you have the source code for the program whose execution you're trying to automate, you'll most likely have to do it on OS level.

It could be achieved though by creating a ram disk. If you're on Linux for instance, it's not that complicated. Have a look at this link: Linux RAM Disk: Creating A Filesystem In RAM.

I suppose that another alternative would be to let your Java program create a named pipe and pass these as the paths to the automated program.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜