tags:

views:

43

answers:

1

After running one executable file from my gui application using swing in java, i want to display running commentary of cmd in my textarea which i have taken on my gui applcation in lower half portion .How can i do it . This is my code i have written for my Run button for running .exe file:-

private void runActionPerformed(java.awt.event.ActionEvent evt) {                                    
        System.out.println( "Running" );
        try
        {
            String [] command    = { "cmd.exe", "/c", "start",
                                     "runMatness.bat",
                                     "inputfile=" + myFilePath,
                                     "dbreporting=false" };
            Process myProcess    = Runtime.getRuntime().exec(command);
            BufferedReader input =
            new BufferedReader (new InputStreamReader(myProcess.getInputStream()));
            while ((line = input.readLine()) != null)
            {
                displayresult.append(line);
            }//while
            input.close();
        }// eof try
        catch (Exception err)
        {
            err.printStackTrace();
        }//eof catch

where displayresult is my textarea.

+1  A: 

Be sure after every

displayresult.append(line);

to call:

java.awt.Container#validate()

method of the enclosing container. Container is the component which receives your displayresult:

someContainer.add(displayresult);
Boris Pavlović
Nice answer, I have done a similar thing before.
Calm Storm