javaunixheap-dumpjmap

JMAP -dump not excuted on java: runtime.exec()


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();
    }
}

Solution

  • 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.