Search code examples
javacommunicationd

Is this a good design for Java and C/D to communicate?


I have a java program where certain parts are computationally intensive. I wish to make that part (which essentially generates an image according to some text data) in C/D. (Multiple instances of the C program might be running at the same time).

Now, I want to be able to track the progress of the C/D program, so the java code needs to read the status (progess, errors) of the C/D program somehow.

My idea is to use the environment variables in the OS, to store the status, "TIME_LEFT=2h10m42s" sort of. Questions:

Is this a good idea, or is there something really bad about this design? Are there some alternatives, (using sockets, stdin/stdout, other)?

EDIT: The Java works as a front-end, so the C/D code should NOT include anything specifically written for Java. The C/D code is essentially a stand-alone program, Java (or other) provides with GUI.


Solution

  • You cannot use environment variables for this, as you cannot communicate environment variables to another program by other than setting it before you start a new process. So you can't run a C program that changes environment variables that your parent java program can see.

    Write line based status to stdout in your C (or D) program rather and read it in your java program.