-3
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();

Help me in understanding the variables. like (VAR1,myvalue),othervar,mydir

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • check [ProcessBuilder](http://docs.oracle.com/javase/7/docs/api/java/lang/ProcessBuilder.html) class. You are building command which will be excuted on shell. – Nandkumar Tekale Oct 10 '12 at 10:22

1 Answers1

1
pb.environment()

contains your environment variables for the current session. For this process to run you are adding and removing variables. When process.start() is called it will be able to use them

To quote the docs

an environment, which is a system-dependent mapping from variables to values. The initial value is a copy of the environment of the current process (see System.getenv()).

In general yoru code is running myshellScript.sh with arguments of MyArg1 and MyArg2 under a modified environment.

RNJ
  • 15,272
  • 18
  • 86
  • 131