2

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 ?

Alex Abdugafarov
6,5227 gold badges39 silver badges60 bronze badges
asked Feb 1, 2012 at 11:19

2 Answers 2

5

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.

answered Feb 1, 2012 at 11:45
Sign up to request clarification or add additional context in comments.

1 Comment

+1 for KISS approach - if you just want to pass a value, pass a value 8=}
5

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

answered Feb 1, 2012 at 11:25

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.