import java.io.*;class S extends Thread {
StringBuffer sb = new StringBuffer();
InputStream is;
String type; S(InputStream is, String type) {
this.is = is;
this.type = type;
}
public void run() {
try {
//StringBuffer sb = new StringBuffer();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line = null;
while ((line = br.readLine()) != null){
//System.out.println(type + ">" + line);
sb.append(type + ">" + line + " \n ");
}
} catch (IOException ioe) {
ioe.printStackTrace();
}
}

}public class Demo {
public static void main(String args[]) {
try {
String osName = System.getProperty("os.name");
String[] cmd = new String[3];
if (osName.equals("Windows XP")) {
cmd[0] = "cmd.exe";
cmd[1] = "/C";
}
Runtime rt = Runtime.getRuntime();
System.out.println("Execing " + cmd[0] + " " + cmd[1] + " "
+ cmd[2]);
Process proc = rt.exec("\"C:/135ftp/ping.bat\"");
S e = new S(proc
.getErrorStream(), "错误信息"); // 错误信息打印?
S o = new S(proc
.getInputStream(), "终端信息"); // info信息打印
e.start();
o.start();
int exitVal = proc.waitFor();
System.out.println("ExitValue: " + exitVal);
} catch (Throwable t) {
t.printStackTrace();
}
}
}
现在是System.out.println打印输出信息,要改成在swing中显示S类中的sb这个StringBuffer,应该如何修改才能得到啊,谢谢。 

解决方案 »

  1.   

    System.out.println(e.sb);
    System.out.println(o.sb);
      

  2.   

    现在是System.out.println打印输出信息,要改成在swing中显示S类中的sb这个StringBuffer,应该如何修改才能得到啊,谢谢。 
    ===========================
    这个有什么问题吗?将StringBuffer的值赋给swing上的一个控件不就行了么?
      

  3.   


    谢谢问题是,我现在在main中调用那个stringbuffer都打不出
      

  4.   


    调度过了,如果在main中没打印出,在run方法中才行。意思是说我得通用swing调用main类似的方法去显示Stringbuffer,不知道我说清楚问题没。谢谢各位 。