简体   繁体   中英

Grab CloudCompare Command Line Output with Java ProcessBuilder

I'm playing a bit around with a small JAVA gui for the command line mode of cloudcompare .

Therefore I'm using a short snippet like these:

var processBuilder = new ProcessBuilder();
try {
    var process = processBuilder
             .command("open", "-a", "CloudCompare.app", "-n",
                      "--args", "-NO_TIMESTAMP", "-C_EXPORT_FMT", "LAS",
                      "-O", "/Users/se/pcl_1.las",
                      "-O", "/Users/se/pcl_2.las",
                      "-MERGE_CLOUDS")
             .start();
    
    String error, line;

    BufferedReader inputStream = new BufferedReader(new InputStreamReader(process.getInputStream()));

    while ((line = inputStream.readLine()) != null) {
        System.out.println("line = " + line);
    }

    BufferedReader errorStream = new BufferedReader(new InputStreamReader(process.getErrorStream()));

    while ((error = errorStream.readLine()) != null) {
       System.out.println("error = " + error);
    }

    var ret = process.waitFor();

    System.out.printf("Program exited with code: %d", ret);

} catch (IOException | InterruptedException e) {
      e.printStackTrace();
}

But if I run it on macOS the command line window opens, the process runs normal, but I can't grab any of the informations in it. There is an option to write log files from cloudcompare. That works - the log file shows that all cloud processing steps are done.

Does anybody knows, how to grab the command line output?

带有信息和错误字符串的 cloudcompare 命令行窗口

As mentioned here , the /usr/bin/open command is not an option to grab the stdinput stream.

I change the command to /Applications/CloudCompare.app/Contents/MacOS/CloudCompare and it works.

The next question is, how to grab the InputStream with a thread. I tried some stack overflow topics, but it doesn't work at the moment, to get the output stream in realtime. It is flushed at the end of the CloudCompare process.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM