Skip to main content

How to get a realtime output of a process when it call using Runtime.exec()

No replies
Joined: 2007-12-03


How to get a real-time output (STDOUT) of a process when it execute using Runtime.exec()? We have developed java web based application deployed on WAS running on AIX server which calls a script using Runtime.exec() in servlet. Through the GUI screen when clicking on submit it invoke the script on the AIX server where application running. Currently it gives the STDOUT of the script on the GUI at the end of the script execution. Since the script execution of takes a long time (3-5 minutes), and the output (script output) gives only after 3-5 minutes user cannot identify what’s going on during that time. So looking for a solution to get a real-time output on the application's GUI. Is there any other way to get this?

Attaching herewith the current logic we have used in program, And our ultimate aim is TO SHOW USER CONCURRENT STDOUT on the application GUI screen.

// consoleString bind to TextArea

private StringBuffer consoleString;

// action for submit button

public String doSubmitAction() {

try {
} catch (IOException e) {
} catch (InterruptedException e1) {
renderedFlag = false;
return "";

private String getCommand() {

StringBuffer buffer = new StringBuffer();
ConfigurationManager configManager;
try {
configManager = ConfigurationManager.getInstance();
Resource resourceSeverConf = configManager.getResource(SERVER_CONF);
buffer.append(resourceSeverConf.getParameter("command") + " ");
buffer.append(getCbOperation().getValue() + " ");
buffer.append(getCbProjectName().getValue() + " ");
buffer.append(getCbStage().getValue() + " ");
buffer.append(getCbLocation().getValue() + " ");
buffer.append(getIpTxtBaseLine().getValue() + " ");
} catch (Exception e) {
return buffer.toString();

private void runCommand(String cmd) throws IOException, InterruptedException {
consoleString = new StringBuffer("");
// set up list to capture command output lines
// start command running
Process proc = Runtime.getRuntime().exec(cmd);
// get command's output stream and
// put a buffered reader input stream on it
InputStream istr = proc.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(istr));
// read output lines from command
String str;
while ((str = br.readLine()) != null) {
consoleString.append(str + "\n");
// wait for command to terminate
// check its exit value
// if (proc.exitValue() != 0)
// System.err.println(proc.exitValue() + "exit value was non-zero");
// close stream