Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top