Question

Trying to execute a .bat file from an activity rule

I'm trying to execute a .bat file from an activity rule. The logic in a similar post is not working as a .bat. I've tried several ways to get it to run. It doesn't throw an error, but the Java step does not seem to execute the .bat file. Any help is appreciated. I'm using PRPC 7.1.8. I have to execute a .bat file, so not doing it is not an option.

Logic 1

ProcessBuilder pb = new ProcessBuilder("d:\\DEV\\Forms\\PrintPageToPDF_F-9015.bat");

try{

Process process = pb.start();

}

catch(java.io.IOException ioEx) {

oLog.error("WritePDFScriptFiles - ", ioEx);

}

Logic 2

String path="cmd /c start d:\\DEV\\Forms\\PrintPageToPDF_F-9015.bat";
Runtime rn=Runtime.getRuntime();
Process pr=rn.exec(path);

Logic 3

String[] cmdArray = new String[3];
cmdArray[0] = "cmd.exe";
cmdArray[1] = "/c";
cmdArray[2] = "d:\\DEV\\Forms\\PrintPageToPDF_F-9015.bat";
Runtime.getRuntime().exec(cmdArray);

Correct Answer
March 7, 2019 - 10:54am

From the first link from Santanu, I was able to get the batch file to execute.  Thanks!

Comments

Keep up to date on this post and subscribe to comments

Pega
February 20, 2019 - 7:22am

Hello

There is no OOTB way. You need to write your custom java code in activity to get it done. 

Just some pointer. 

https://www.opencodez.com/java/how-to-execute-bat-file-from-java.htm

https://coderanch.com/t/371842/java/execute-BAT-java-Application

 

March 7, 2019 - 10:54am

From the first link from Santanu, I was able to get the batch file to execute.  Thanks!

May 22, 2019 - 9:33am
Response to DavidD95

Hi David, Greetings!
I am also trying to achieve this, can you pass me the exact code for the same please.

Thanks,
Harsha K

May 23, 2019 - 7:43am
Response to Harsha K

nevermind, I have manged to achieve this, Thanks for the post!

Regards,
Harsha K

August 16, 2019 - 11:30am

All,

This is my logic to accomplish this in a Java step in an activity rule.  It works in my Development and QA environments on a single node, single server instance, but not in my Model and Production, 2 node, 2 server environments.  It does not open and execute the .bat file.  In Task Manager, I don't see the cmd window opening in execution.  In Development, I do.  I opened a SR with Support and they said it was J2EE security, but the settings are the same.  Any ideas are welcomed.

try{

String[] cmdArray = new String[4];

cmdArray[0] = "cmd.exe";

cmdArray[1] = "/C";

cmdArray[2] = "Start";

cmdArray[3] = "D:\\PDFGen\\FORMS_PrintPageToPDF_F-118503.bat";

Runtime.getRuntime().exec(cmdArray);

    oLog.error("WritePDFScriptFiles - BATCHFILEPATH is " + BATCHFILEPATH);

  oLog.error("WritePDFScriptFiles - After execution of cmd");

try {

Thread.sleep(5000);

  catch (Exception e) {

oLog.error("WritePDFScriptFiles - ", e);

}

}

catch(Exception ioEx) 

  oLog.error("WritePDFScriptFiles - ", ioEx);

  throw new PRRuntimeException(ioEx);

}