How to get input from Putty to Java?

2019-09-20 02:17发布

问题:

I am quite new to Ubuntu and shell programming. I am using putty to execute vmstat and iostat commands on Ubuntu. I need to execute those commands in java (Windows environment) and get an InputStream of the result. Is it possible?

回答1:

Yes. Use plink (a command-line interface to the PuTTY back end).

For example,

plink remote_host "ls -l"

I've successfully used this to, from a Windows-based TFS Build, execute an Android build on a Linux box. So it's possible to work with the output from plink programatically.

Here's an example of how to call a shell command from within Java.