I am attempting to write a program that will read the output from a java .jar file and also give it input from time to time. Basically I am hoping to make a program that will execute certain functions when certain output is encountered.
The .jar file wasn't created by me, and I don't have the source code, so I have to use it as-is. After doing some research I decided using fork()
and execl()
in conjunction with pipes was the method I would need to use and I created a small program that successfully does this with a hello world program. Just as I was getting ready to modify it to run the .jar program I realized that the .jar isn't executable on its own, I have to execute it through java and so now I'm unable to figure out how to make execl()
work with the .jar.
I have tried to figure out how to make execl() run java and use an argument that specifies the jar file to execute like so:
execl("java","java","jar myprog.jar",NULL);
I don't know if this method will work, though. If it will I don't know what path to use. I have seen some people recommend using JNI for similar purposes, but none of them seemed to quite fit with what I was doing and after researching it a bit I'm not totally sure that would be the best way to go. popen() seems like another possibility, but I have yet to find anything that explains how to use it well.
Any advice would be greatly appreciated.