calling R script from java

后端 未结 5 1961
梦如初夏
梦如初夏 2020-12-08 05:36

I would like to call an R script from Java. I have done google searches on the topic, but almost all of the results I have seen would require me to add a dependency to some

5条回答
  •  鱼传尺愫
    2020-12-08 06:01

    Do not wait for the process to finish with Thread.sleep()...

    Use the waitFor() method instead.

    Process child = Runtime.getRuntime().exec(command, environments, dataDir);
    
    int code = child.waitFor();
    
    switch (code) {
        case 0:
            //normal termination, everything is fine
            break;
        case 1:
            //Read the error stream then
            String message = IOUtils.toString(child.getErrorStream());
            throw new RExecutionException(message);
    }
    

提交回复
热议问题