方法一
public static void main(String[] args)
{
InputStream ins = null;
String[] cmd = new String[]{
try
{
Process process = Runtime
// cmd 的信息
ins = process
BufferedReader reader = new BufferedReader(new InputStreamReader(
ins));
String line = null;
while ((line = reader
{
// 輸出
System
}
int exitValue = process
System
// 關閉
process
}
catch (Exception e)
{
e
}
方法二
class StreamDrainer implements Runnable
{
private InputStream ins;
public StreamDrainer(InputStream ins)
{
this
}
public void run()
{
try
{
BufferedReader reader = new BufferedReader(new InputStreamReader(ins));
String line = null;
while ((line = reader
{
System
}
}
catch (Exception e)
{
e
}
}
}
public class CMD
{
public static void main(String[] args)
{
// String[] cmd = new String[] {
//
String[] cmd = new String[]
{
try
{
Process process = Runtime
new Thread(new StreamDrainer(process
new Thread(new StreamDrainer(process
process
int exitValue = process
System
}
catch (Exception e)
{
e
}
}
}
本篇文章來源於 :劉志猛博客 原文鏈接
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26793.html