Home  >  Article  >  Java  >  How to implement dos command operation in java

How to implement dos command operation in java

little bottle
little bottleOriginal
2019-05-20 15:44:043273browse

How to implement dos command operation in java

本篇文章中主要是和大家讲述java如何实现操作dos命令,感兴趣的朋友卡伊了解一下。下面一起进入正文吧!

读取文件中的命令:

package com;
import java.io.InputStream;
public class cmd {
            public static void main(String[] args) {
            String path = "D:\\cmd.bat";
            Runtime run = Runtime.getRuntime();
            try {
                //run.exec("cmd /k shutdown -s -t 3600");
                Process process = run.exec("cmd.exe /k start " + path);
                InputStream in = process.getInputStream();
                while (in.read() != -1) {
                    System.out.println(in.read());
                }
                in.close();
                process.waitFor();
            } catch (Exception e) {
                e.printStackTrace();
            }
    }     
}

How to implement dos command operation in java

运行结果如下:

How to implement dos command operation in java

相关学习推荐:java基础教程

The above is the detailed content of How to implement dos command operation in java. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn