Java – collect Linux command output

I'm on a @ L_ 404_ 0 @ on the machine I have a java program that will run some linux commands, such as PS, top, list or free - M

The way to run commands in Java is as follows:

Process p = Runtime.getRuntime().exec("free -m");

How to collect output through a java program? I need to process the data in the output

Solution

Using process Getinputstream () gets the standard InputStream representing the newly created process

Note that starting / running external processes from Java can be tricky and flawed

They are described in this excellent article, which also describes their methods

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>