Get output from a process

后端 未结 5 1396
心在旅途
心在旅途 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:09

    1. use public static void main (not Object as return type)
    2. Serialize the object using ObjectOutputStream (all necessary examples are in the javadoc)
    3. The only thing different from the example is the construction - construct it like ObjectOutputStream oos = new ObjectOutputStream(System.out);
    4. in the program calling exec(), get the output with process.getOutputStream()
    5. Read in an ObjectInputStream based on the already retreived OutputStream (check this)
    6. Deserialize the object (see the javadoc of ObjectInputStream)

    Now, this is a weird way to do it, but as I don't know exactly what you are trying to achieve, it sounds reasonable.

提交回复
热议问题