JAVA之执行cmd命令

时间:2023-04-08 23:12:48

感言在前:时隔好久没有更新博客园了,忙东忙西也没忙出个什么之所以然来。回首过去一两个月,只能用“疲倦”两个字来形容,而且是身心疲惫。每天11、12个小时的工作我都没觉得烦,但是总是想克服却又很难克服的是我老是“贪睡”,都快要变成“瞌睡虫”了!一直都是“睡不饱”的无精打采的状态去过单调而且重复的生活,我很佩服自己没垮掉就算了还能坚持到现在实属不容易啊!毕竟年轻气盛精力旺盛这都扛的住。时间飞逝地很快,有苦也有乐,有酸也有甜。毕竟,生活就是这样,苦中作乐,平凡也精彩。

好了,矫情的话就说到这。百忙之中,我还是记得抽些时间来更新博客园。

class ExecCmd {
public static void main(String args[]) {
Runtime run = Runtime.getRuntime();
Process process = null;
try {
process = run.exec("notepad"); // 执行cmd命令
process.waitFor();
} catch (Exception e) {
System.out.println("Error executing notepad.");
}
System.out.println("Notepad returned " + process.exitValue());
}
}