Posted: 15 Oct 2019 2:13 EDT Last activity: 23 Oct 2019 5:21 EDT
Running Java CLI From Pega
I'm still new to Pega and learning. I have a Java application that I wrote that takes command line arguments. Is there a way, other than building a UI and interrogating that UI, to run my java program from Pega? What I want to do is something like have Pega run a command such as: "c:\java-jar-location\java -jar com.mydomain.Class arg1 arg2...". How can I do this with Pega?
Assuming you just wanted to launch a process and not interrogate it, you would use the static method from .Net; Process.Start. You can add this to your Toolbox, by right-clicking on an empty area (I use the General section for these myself) and selecting "Choose items...". The select the "Pega Robot Static Members" tab. Next, select the "From Global Assembly Cache" radio button. From the "Assembly" combo box, select "System". Locate the "Process" node and select the "Start" method by clicking into the check box. Click "Ok". You can now drag this method out to your automation. When you choose an overload, select the appropriate one; which is normally the method taking a "fileName" and "arguments".
Thank you. I got this to work but only if I made my JAR file an executable. Otherwise, Pega loaded a modal asking if I wanted to use a JRE when I just passed on arguments to the JAR file. However, it works as an executable so that's good. In my main class, there's a method System.exit(1). Is there anyway to get Pega to wait for this message so I can send back en error or a success message from my Java class and be sure that the system knows how to proceed? I have a message dialog modal showing in Pega and Pega shows it immediately even though my Java objects are still doing work before. It seems that the result value of System.Process does not exist before the system exits...
The way to get an exit code from the Process is to extract a proxy from the result. Then add a "waitForExit" method to the automation and the proxy will then be populated with whatever exit code the system gave. Awesome!