Question

5
Replies
2361
Views
OnkarY33 Member since 2013 17 posts
Infosys
Posted: 3 years ago
Last activity: 3 years ago
Closed
Solved

How can I execute a shell script from Pega?

I have a requirement where I need to execute a shell script from Pega. This shell script exists on the Pega server/box and takes multiple(5-five) parameters. I have found below piece of Java Code on this forum which has been accepted as correct answer. But when I am trying to use this for my requirement I face below problems or have below questions. Any help is most appreciated

Clarifications needed for below Code:

1. When I try to save this code as is in Java step in an activity I get - "File cannot be resolved to a type"

2. In the 1st line as I see the name of the shell script and arguments are being passed. As in my case the script takes 5 parameters. How should I pass these? And what about the sequence of parameters?

3. Also I did not understand below part. What do I need to add to the Map env?

Map<String, String> env = pb.environment();
env.put("VAR1", "myValue");
env.remove("OTHERVAR");
env.put("VAR2", env.get("VAR1") + "suffix");

Piece of Java code found on this forum:

ProcessBuilder pb = new ProcessBuilder("myshellScript.sh", "myArg1", "myArg2");
Map<String, String> env = pb.environment();
env.put("VAR1", "myValue");
env.remove("OTHERVAR");
env.put("VAR2", env.get("VAR1") + "suffix");
pb.directory(new File("myDir"));
Process p = pb.start();

PS- I am using Pega 7.3. Let me know if any more details are needed.

Data Integration Java and Activities
Moderation Team has archived post
Share this page LinkedIn