Running a Jar with Java ProcessBuilder gives me null output -


i have been trying following code work.

package com.compressor;   import java.io.bufferedreader;  import java.io.file;  import java.io.inputstreamreader;   public class jscompressor {   public static void main(string[] args) {      try {          string currentdir = system.getproperty("user.dir");          string[] commands = { "java", "-jar","yuicompressor.jar"};          processbuilder pb = new processbuilder(commands);         pb.directory(new file(currentdir));          process p = pb.start();          bufferedreader output = new bufferedreader(new inputstreamreader(p.getinputstream()));         system.out.println("result : " + output.readline());                                   } catch (exception ex) {         ex.printstacktrace();     }  }   } 

my project directory looks shown in image below :

enter image description here

but still when run program inside eclipse gives me null output given below :

result : null

i have tried googling several options without success. please point out doing wrong here ?.

i jar testing indeed runnable , gives output when run in command line. need able run jar programetically. please ?.

i think want change

string[] commands = { "java", "-jar","yuicompressor.jar"}; 

to

string[] commands = { "java", "-jar", jarpath}; 

since that's path yuicompressor.jar. also, should use thread read process output - , wait process complete.

final process p = pb.start(); // start thread read output. new thread(new runnable() {   public void run() {     bufferedreader output = new bufferedreader(         new inputstreamreader(p.getinputstream()));     string line;     system.out.print("result : ");     while ((line = output.readline()) != null) {      system.out.println(line);     }   } }).start(); p.waitfor(); 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -