Java代码如何运行cmd.exe呢?
下文笔者讲述使用java代码云习惯cmd.exe程序的方法分享,如下所示
使用 Runtime.getRuntime().exec(command); 方法即可运行cmd.exe例:运行cmd.exe
public static void main(String[] args) {
String path = "D:\\test.bat";
Runtime run = Runtime.getRuntime();
try {
// run.exec("cmd /k shutdown -s -t 3600");
Process process = run.exec("cmd.exe /k start " + path);
InputStream input = process.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(input));
String szline;
while (szline = reader.readLine()!= null) {
System.out.println(szline);
}
reader.close();
process.waitFor();
process.destroy();
} catch (Exception e) {
e.printStackTrace();
}
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。


