1

I am trying to execute a jar using process builder but it is giving comma in between each term

ProcessBuilder processBuilder=new ProcessBuilder("Java","-jar","D:/tools/censeo.jar","SourcePath" +javaFileDir+ "-OutputType","xml","OutputPath"+javaFileDirectory+"\"");

Process process=processBuilder.start();

Is it correct format of using processbuilder for executing jar?

Reimeus
  • 152,723
  • 12
  • 195
  • 261
  • 1
    `java` command should be lowercase – Reimeus Jun 06 '13 at 02:37
  • @Reimeus Depends on the OS, but it never hurts ;) – MadProgrammer Jun 06 '13 at 02:55
  • The code seems to work OK on my system (except that I don't have the jar file, obviously). Can you post the command line you're getting and why you think it's wrong? – sigpwned Jun 06 '13 at 03:09
  • @sigpwned I tried to print command but it is printing like this Java,-jar,D:/tools/censeo.jar,-SourcePath D:/abc-OutputType,xml,-OutputPath D:/abc – user2214846 Jun 06 '13 at 15:27
  • That looks like the result of printing a `List` to `System.out`. Are you printing a `List` and not a String? (e.g., `System.out.println(processBuilder.command());`?) If so, that's expected -- it's just what a `List` converted to a String looks like. Once you've created your `Process` (call it `p`), try printing the result of reading say 1000 characters from `p.getErrorStream()`. This will show the contents of the underlying shell's `stderr`, which will likely tell us what's going on. If that comes up empty, make sure you're reading properly, and the try reading from p.getOutputStream()`. – sigpwned Jun 06 '13 at 17:31
  • @sigpwned No I am not printing any list.Can you please tell me the changes that I can make it to above processbuilder command. – user2214846 Jun 06 '13 at 18:50
  • note: see this question http://stackoverflow.com/questions/309424/read-convert-an-inputstream-to-a-string for how to print the error stream. – martin jakubik Apr 10 '14 at 16:36

0 Answers0