0

How can I start an .exe file with parameters I get from an output of an .jar file.

I know how I can start my java program with parameters within a batch:

java -jar javaProgram.jar %1 %2 %3 %4

But how can I get a result of the java code for example "Yes" or "No" to start a new program .exe within the same batch?

I this even possible?

IanGSY
  • 3,664
  • 1
  • 22
  • 40
akBen
  • 37
  • 1
  • 7
  • Not your exact use case, but [this reference may be useful](https://gist.github.com/crowcoder/613104a403cec7f503fc#file-webjobjar-cs) – Crowcoder Aug 21 '18 at 14:02
  • If the output is simply yes and no, you should consider using return codes. See this. https://stackoverflow.com/questions/334879/how-do-i-get-the-application-exit-code-from-a-windows-command-line – killjoy Aug 21 '18 at 14:11
  • Thanks for your information. I am using the ProcessBuilder now. – akBen Sep 03 '18 at 09:18

1 Answers1

0

Your exe must always return an int use error level:

 IF ERRORLEVEL 1 (
    REM do something here to address the error
  )

See more here

To exec exe file in java use this code:

ProcessBuilder pb = new ProcessBuilder("your exe file here ", "myArg1", "myArg2");
pb.directory(new File("your path here"));
Process p = pb.start();

see more about ProcessBuilder here

JavaSheriff
  • 7,074
  • 20
  • 89
  • 159