How to call the linux command "source FILE_NAME" from Java? -


actually have 2 commands :

  1. source file_name
  2. install abcd

before executing second command, need execute first one. tied execute both command using runtime.getruntime().exec(cmd) methos, second command failed, since depends on first one. tried many combinations, not succeeded. can please me?

you're executing 2 separate exec commands, spawning separate processes, , whatever in first process not visible second. resolve putting of commands script (bash, ksh, etc) , call once java program.

paramterize script can pass arguments.

here's on writing first shell script


[edit] mentioned @rnj can @ using processbuilder pass in environment variables each of processes spawned. fine if can specify name of file being created ahead of time. example code taken api link above...

 processbuilder pb = new processbuilder("mycommand", "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(); 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -