Good Day Everyone, I have a program (lets call it 'A'), which is called from an ANT script using java. This program uses Runtime.getRunTime.exec("batFile.bat"). The .bat file in-turn calls another java file (lets call it 'B'). Now, here comes the problem.
Is there a way in which B can access instance variable of A ?
2 Answers 2
If you know the value of the variable in process A before it launches process B, then you could share that value in a number of ways.
Pass it as a command line argument, e.g.:
String[] cmd = {"batFile.bat", variableValue};
Runtime.getRunTime.exec(cmd);
Set it as variable in the environment of B's process, e.g.:
String cmd = "batFile.bat";
String[] envp = {"VARIABLE="+variableValue};
Runtime.getRunTime.exec(cmd, envp);
Write the value to a file in process A, read the file in process B.
1 Comment
No. Because the .bat file is creating a new jvm process. May be you want to use DB to share the data.