简体   繁体   中英

Java Inter process communication

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 ?

No. Because the .bat file is creating a new jvm process. May be you want to use DB to share the data.

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, eg:

String[] cmd = {"batFile.bat", variableValue};
Runtime.getRunTime.exec(cmd);

Set it as variable in the environment of B's process, eg:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM