1
在我的gui应用程序中使用swing运行java中的一个可执行文件, 我想在我的textarea中显示正在运行的cmd文件在我的gui applcation下半部分。我该怎么做。 这是我的代码我有我的运行按钮书面运行.exe文件: -如何在java中使用swing显示在gui应用程序上设计的cmd文件的运行解释
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
其中displayresult是我的textarea。
不错的答案,我以前做过类似的事情。 – 2010-02-19 11:45:47