Java and Unix

Question:
Is it possible to use Java to execute a command on Unix and get the output from that command?

Answer:
Yes. The java.lang.Runtime class has various exec() methods thatcan be used to execute an operating system command. They eachreutrn a java.lang.Process instance. The Process class contains themethods getInputStream(), getOutputStream(), and getErrorStream(),which can be used to read and write standard input, output, and error.Look at the example accompanying the question with topic”Piping External Process Output” for more details.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: