可以,通过执行一个本地
/**
通过LANG包中的Process类实现执行一个本地命令!
*/
import java.io.*;
import java.util.*;
public class ShellCommand
{
private Process process;
public String getProcessContent()
{
String Res=null;
if (process!=null)
{
try
{
BufferedReader in=new BufferedReader(new InputStreamReader(process.getInputStream()));
String temp=in.readLine();
while (temp!=null)
{
Res=Res+"/n"+temp;
temp=in.readLine();
}
}
catch (IOException exp)
{
System.out.println(exp.toString());
}
}
return Res;
}
public void execCommand(String strShell){
try{
if(process!=null){
killProcess();
}
Runtime sys= Runtime.getRuntime();
process=sys.exec(strShell);
}catch(Exception e){
System.out.println(e.toString());
}
}
/**
杀死该进程
*/
public void killProcess(){
if(process!=null){
process.destroy();
process=null;
}
}
public static void main(String[] args)
{
ShellCommand sc=new ShellCommand();
sc.execCommand("ping 127.0.0.1");
System.out.println(sc.getProcessContent());
System.exit(0);
}
}