How to execute the shell script program file from the Java class -



How to execute the shell script program file from the Java class -

i have written shell script file extracts files, please see below.

file name: unzip.sh

#/bin/sh cd /home/zip; unzipdir=/home/unzip/; in *.zip; unzip "$i" -d "$unzipdir" rm "$i"; done;

this shell script executes sucessfuly on putty,

$> ./zip.sh

as wanted execute script java class while have tried several ways invoke/execute shell script file it's not executing. please see below java code.

//first seek file executordirectory = new file("/home/zip"); processbuilder processbuilder = new processbuilder("./unzip.sh"); processbuilder.directory(executordirectory); process p = processbuilder.start(); p.waitfor() //second seek process p = runtime.getruntime().exec("/home/zip/unzip.sh");

the problem fail business relationship process' standard output/error (as mentioned @yazan in comments). need .get{output,error}stream() created process , read them (even if discard it).

the real problem utilize external shell script exclusively doable in java itself. see this page gives illustration of how extract zip file exclusively java code; delete file, utilize files.delete().

java shell

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -