Get output from a process

后端 未结 5 1398
心在旅途
心在旅途 2020-12-07 05:04

This is a second part to my question here.

I now have a process but I want to know how to get the output from the process?

String filename = matlab.         


        
5条回答
  •  我在风中等你
    2020-12-07 05:10

    You could do System.setOut(new PrintStream(p.getOutputStream())) if you'd like to have the process print its results directly to standard output. Of course, this will override the old standard output. But you could also do other things with the process's output stream, like have a thread that reads from it.

    A problem with your code is that the main function of a class must be of type void, and will return nothing. You will not be able to pass Java objects between processes, as they are running in different JVMs. If you must do this you could serialize the object to disk, but I imagine you don't even need to run this in a separate process.

提交回复
热议问题