方法一:
public static void main(String[] args)
{
InputStream ins = null;
String[] cmd = new String[]{ "cmd.exe", "/C", "ipconfig" };
try
{
Process process = Runtime.getRuntime().exec(cmd);
// cmd 的信息
ins = process.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(
ins));
String line = null;
while ((line = reader.readLine()) != null)
{
// 输出
System.out.println(line);
}
int exitValue = process.waitFor();
System.out.println("返回值:" + exitValue);
// 关闭
process.getOutputStream().close();
}
catch (Exception e)
{
e.printStackTrace();
}