How to pass arguments to a shell script using java? -


i have written code calls shell script:

 processbuilder pb2=new processbuilder("/home/abhijeet/sample1.sh");  process script_exec = pb2.start();  pb2.redirecterror(); 

code works me , executes script.

this script takes 2 arguements 1: input file 2: seqs , in pattern like:

 sample1.sh -ip=abc.txt --seqs=20 

shell script interactive one, asks many parameters , have changed it's code , pass values arguements it. complete format should like:

db=abc outformat=1 threads=10 sample1.sh --ip=abc.txt --seqs=20

so how can execute script using java? there other way call interactive script using java?

you can try this:

 processbuilder pb2=new processbuilder("/home/abhijeet/sample1.sh --ip=abc.txt --seqs=20");  process script_exec = pb2.start();  outputstream in = script_exec.getoutputstream();  in.write("abc".getbytes());  in.write("1".getbytes());  in.write("10".getbytes());  in.flush();  in.close(); 

this code writes abc, 1 , 10 process input.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -