public String runCommand(String cmdExp){
InputStream[] tmpstm=new InputStream[2];
String[] Info=new String[2];
InputStreamReader isr=null;
BufferedReader br=null;
String okInfo="";
String errInfo="";
try {
//String osName =System.getProperty("os.name");
//System.out.println("osName:"+osName);
String[] cmd=new String[3];
cmd[0]="cmd.exe";
cmd[1]="/C";
cmd[2]=cmdExp;
//System.out.println("正在执行的是: "+cmd[0]+" "+cmd[1]+" "+cmd[2]);
Runtime rt=Runtime.getRuntime();
Process proc=rt.exec(cmd);
// any error message
//gobbler errgobbler=new gobbler(proc,proc.getErrorStream(),"error");
tmpstm[0]=proc.getInputStream();
tmpstm[1]=proc.getErrorStream();
// any output
//gobbler outgobbler=new gobbler(proc,proc.getInputStream(),"output");
// errgobbler.start();
// outgobbler.start();
isr=new InputStreamReader(tmpstm[0]);
br=new BufferedReader(isr);
String line=null;
while((line=br.readLine())!=null){
// System.out.println("*******"+line);
okInfo+=line+"\n";
}
line=null;
isr=new InputStreamReader(tmpstm[1]);
br=new BufferedReader(isr);
while((line=br.readLine())!=null){
// System.out.println("*******"+line);
errInfo+=line+"\n";
}
//Info[0]=okInfo;
//Info[1]=errInfo;
int exitVal=proc.waitFor();
// System.out.println("exitVal "+exitVal);
} catch (IOException e) {
e.printStackTrace(); //To change body of catch statement use Options | File Templates.
} catch (InterruptedException e) {
e.printStackTrace(); //To change body of catch statement use Options | File Templates.
}
String mstmp="";
if (okInfo!=null) mstmp=okInfo;
if (errInfo!=null) mstmp+=errInfo;
return mstmp;
}
InputStream[] tmpstm=new InputStream[2];
String[] Info=new String[2];
InputStreamReader isr=null;
BufferedReader br=null;
String okInfo="";
String errInfo="";
try {
//String osName =System.getProperty("os.name");
//System.out.println("osName:"+osName);
String[] cmd=new String[3];
cmd[0]="cmd.exe";
cmd[1]="/C";
cmd[2]=cmdExp;
//System.out.println("正在执行的是: "+cmd[0]+" "+cmd[1]+" "+cmd[2]);
Runtime rt=Runtime.getRuntime();
Process proc=rt.exec(cmd);
// any error message
//gobbler errgobbler=new gobbler(proc,proc.getErrorStream(),"error");
tmpstm[0]=proc.getInputStream();
tmpstm[1]=proc.getErrorStream();
// any output
//gobbler outgobbler=new gobbler(proc,proc.getInputStream(),"output");
// errgobbler.start();
// outgobbler.start();
isr=new InputStreamReader(tmpstm[0]);
br=new BufferedReader(isr);
String line=null;
while((line=br.readLine())!=null){
// System.out.println("*******"+line);
okInfo+=line+"\n";
}
line=null;
isr=new InputStreamReader(tmpstm[1]);
br=new BufferedReader(isr);
while((line=br.readLine())!=null){
// System.out.println("*******"+line);
errInfo+=line+"\n";
}
//Info[0]=okInfo;
//Info[1]=errInfo;
int exitVal=proc.waitFor();
// System.out.println("exitVal "+exitVal);
} catch (IOException e) {
e.printStackTrace(); //To change body of catch statement use Options | File Templates.
} catch (InterruptedException e) {
e.printStackTrace(); //To change body of catch statement use Options | File Templates.
}
String mstmp="";
if (okInfo!=null) mstmp=okInfo;
if (errInfo!=null) mstmp+=errInfo;
return mstmp;
}