Here the output of two commands are shown in JTextArea
import java.util.*;
import java.io.*;
import javax.swing.*;
public class Shell {
private static String command = "ls -Als";
private static String command2 = "cat /etc/profile";
private String string="";
public static void main(String[] args) throws java.io.IOException {
JFrame frame=new JFrame("Output");
JTextArea textArea=new JTextArea();
textArea.setEditable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.getContentPane().add(textArea);
frame.setSize(500,800);
frame.setVisible(true);
try {
Process child = Runtime.getRuntime().exec(command);
// Get the input stream and read from it
InputStream in = child.getInputStream();
int c;
while ((c = in.read()) != -1) {
textArea.append(String.valueOf((char)c));
}
in.close();
} catch (IOException e) {
}
try {
Process child = Runtime.getRuntime().exec(command2);
// Get the input stream and read from it
InputStream in = child.getInputStream();
int c;
while ((c = in.read()) != -1) {
textArea.append(String.valueOf((char)c));
}
in.close();
} catch (IOException e) {
}
}
}