java执行dos命令
在这里@Component
public class Gh {
/**Runtime.getRuntime()
* Runtime 程序运行时环境
* getRuntime()获取环境对象
* Process process1 = Runtime.getRuntime().exec("cmd /c net user 123 123");通过运行时环境对象,执行dos命令,返回一个进程对象
* @param args
*/
public static void main(String[] args) {
Process process = null;
Process process1 = null;
try {
process1 = Runtime.getRuntime().exec("cmd /c net user 123 123");
process = Runtime.getRuntime().exec("cmd /c net user 123 123");
InputStream in=process.getInputStream(); //获取DOS下的输出
Scanner scan=new Scanner(in);
while(scan.hasNextLine())
System.out.println(scan.nextLine());
scan.close();
System.out.println("12");
} catch (IOException e) {
e.printStackTrace();
}
}
}插入代码片