import java.io.IOException;
public class Test {
public static void main(String[] args) {
exec("ls",true,true);
}
/**
*
* @param cmd 命令
* @param isOpenWindow 是否打开PowerShell窗口
* @param isFinishExit 如果打开窗口,那么执行完毕后是否自动退出
*/
public static void exec(String cmd,boolean isOpenWindow,boolean isFinishExit){
String args = "";
if (isOpenWindow) {
args = "cmd /c start PowerShell "+cmd;
}else{
args = "cmd /c PowerShell "+cmd;
}
if (isOpenWindow&&!isFinishExit){
args += ";read-host";
}
try {
Runtime.getRuntime().exec(args);
} catch (IOException e) {
e.printStackTrace();
}
}
}
