0

i have tried to execute the 'jmap -dump:format =b; file" command in runtime.exec(), but it wont execute where other commands like date, pwd are working fine. can anyone know why?

public static void commands(String s) {

    runtime=Runtime.getRuntime();


    try {
        System.out.println(" Creating Heap Dump ");
        process=runtime.exec("jmap -dump:format=b,file=D:/heapdump_2012APR10/heapdump_date +%d%b%Y-%H_%M_%S.bin 4478");
        System.out.println("Heap Dump Created. Zipping the file");
        process=runtime.exec("gzip *.bin");
        System.out.println("Succesfully zipped");



    } catch (Exception e) {
        e.printStackTrace();
    }
}
trincot
  • 317,000
  • 35
  • 244
  • 286
Loga
  • 658
  • 1
  • 7
  • 17

1 Answers1

0

You call two consecutively processes

process=runtime.exec("jmap -dump:format=b,file=D:/heapdump_2012APR10/heapdump_date +%d%b%Y-%H_%M_%S.bin 4478");
process=runtime.exec("gzip *.bin");

without waiting that the first one terminates.

And then you don't ever consume the stream of the processes you exec, or check theirs exit code.

So follow the suggestion of @Andrew Thompson and read this article. It explains very well how to launch external process from Java.

dash1e
  • 7,677
  • 1
  • 30
  • 35
  • Thanks,, Dash. But i got another error named "error attaching to core file can't attach to the core file". Thanks. – Loga Apr 16 '12 at 11:23