Question

I am running a tool named "fio" from my java code using process builder.the tool has its source code in C.i need to get values of some variables from the source code of "fio",when i am running the tool in my java code.I tried to search for the solution but could not find any. how can i do it?can "environment variables" for processbuilder help? here is the code i am using

        String line=null;
        ProcessBuilder pb=new ProcessBuilder("fio","inp.fio");
        File f=new File("/home/nikhil/Nikhil");
        pb.directory(f);

        Process p=pb.start();
        InputStream i=p.getInputStream();
        InputStreamReader ir=new InputStreamReader(i);
        BufferedReader bf=new BufferedReader(ir);

        InputStream err=p.getErrorStream();
        InputStreamReader rerr=new InputStreamReader(err);
        BufferedReader bferr=new BufferedReader(rerr);
Was it helpful?

Solution 2

I can use "shared memory" to share the variable value with another new C program i wrote,now i can call a function from this new C program that will return me the value of the variable which is "shared" in my java code using JNI.

OTHER TIPS

I'm going to assume you have access to the code for fio and can rebuild it. One mechanism you could use would be to have fio output the local variable state you are interested in to one of the output streams (stdout or stderr) that you are handling, and parse the values out of it as messages whenever it changes and fio outputs an updated value. That keeps the communication fairly simple.

If you have a lot of complex data, you might want to consider creating a separate communication channel (shared memory, for example, or named pipes, or a socket based connection) for shared state. If you are just interested in some cheap debugging, I'd just go with the first approach by outputting something like

DBG{var1}=<value>

to stderr whenever a value of interest changes, and have your stderr stream handler in Java record the state for use wherever you need it.

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