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.
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);
精彩评论