0

I use process.waitFor to wait for a external tool (CADD, a computational biology tool) to do some calculation under RHEL 6.6

    String cmdStr = "CADD_v1.3/bin/score.sh input.vcf.gz output.vcf.gz"
    try {
        Process p;          
        p = Runtime.getRuntime().exec(cmdStr);
        int exitVal = p.waitFor();
        System.out.println("complete. Return value " + exitVal);
    } catch (Exception e) {
        e.printStackTrace();
    }

    return;

The code print complete immediately without waiting. The exit value is 0. and the calculation doesn't even go to the end (it is initiated since the output.vcf.gz is created, but the output file is always empty).

The cmdStr itself runs OK in terminal.

Suggestions are appreciated. Thanks

Mavershang
  • 1,266
  • 2
  • 15
  • 27
  • Read the `Output/ErrorStream`s to see what output the command generated. Consider using a `ProcessBuilder` which will allow you to redirect the `ErrorStream` through the `OutputStream`, making it easier to manage. Also, you might need to start a shell in which the script can be executed – MadProgrammer Jan 29 '16 at 01:57
  • May be the output of p.waitFor() will give some clue, it should be 0. – SomeDude Jan 29 '16 at 02:10
  • @svasa: yes, it returns 0 – Mavershang Jan 29 '16 at 02:19
  • It looks like your script score.sh is assigning the important work of updating/populating the output file to a sub-process and it is terminating by itself. Look inside your script if it is forking a new process and the parent process is terminating. – SomeDude Jan 29 '16 at 02:23
  • @svasa: Yes it assigned to a subprocess. Is there anyway that I can force it to wait? – Mavershang Jan 29 '16 at 02:28
  • Yes, change the shell script to not put the subprocess in the background. Removal of a trailing `&` for example. – user207421 Jan 29 '16 at 02:41
  • [This](http://stackoverflow.com/questions/3292540/make-parent-thread-wait-till-child-thread-completes-or-timeout) might give some clue. – SomeDude Jan 29 '16 at 02:43

0 Answers0