How to write the input stream of a running java program?

I have a CentOS server that is currently running the java jar application. I need to write a php script to communicate with this running program through its input stream. The java program outputs its output to a log file, so I don't need access to the output stream.

I do not want to restart the program, just get access to the running process and interact with it.

Can someone point me in the right direction?

+4
source share
2 answers

If portability is not important to you, why not create your own channel? I don’t know much about the java application, but I will look at the function / mkfifo / command.

+1
source

First find the ProcessID of the application. You can do this using:

ps -Af | grep java 

Since you are using java, you can feel more comfortable using the jps to find the PID.

I assume that the PID of the running application is 12345. It is enough to issue the command:

 cat >/proc/12345/fd/0 

And everything that you enter will be placed in the standard input of this application. Note that fd contains the file descriptors used by the application, and I believe that the 0th file descriptor will always be stdin .

Using PHP to write to a file (and therefore consuming it as an input by the application) is also possible.

+1
source

All Articles