It's all about the answers!

Ask a question

How can I get the correct exit code from LSCM when calling from Java?


Andy Jewell (24236374) | asked May 20 '14, 12:16 p.m.
 HI. . . I recently started using the Java runTime rather than ant to run lscm commands.  Unfortunately, I can't seem to get the true exit value.  It seems there are a ton of variables to this simple topic including how the java interpreter is called from the batch file, how the batch file exits, whether command extensions are used in the Windows command interpreter, and whether ProcessBuilder or runTime.exec() is used.  There may even be more that I'm not aware of.

If I run the lscm command from the console and run "echo %ERRORLEVEL%", it looks accurate.  But I haven't been able to get this exit value from my java code, it just returns 0 regardless of the success of the command.

Does anyone have a tried and true approach to calling lscm from Java and getting accurate exit values?

Thanks for your thoughts and help!

- Andy

One answer



permanent link
Shashikant Padur (4.3k27) | answered May 20 '14, 11:31 p.m.
JAZZ DEVELOPER
You can use ProcessBuilder and wait for the process to complete. Once the process is complete get the return code in Process.exitValue().

Comments
Andy Jewell commented May 21 '14, 3:12 p.m.

For some reason, that doesn't work.  Does it work for you?  I've tried Apache commons-exec, ProcessBuilder, and runTime.exec -- they all show 0 as the exit status. 



Shashikant Padur commented May 21 '14, 10:46 p.m.
JAZZ DEVELOPER

Yes, we have this in our junit tests and it works fine. 

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.