Java Process 创建linux用户

来源:互联网 发布:tower与其他软件 编辑:程序博客网 时间:2024/05/22 04:37

通过调用shell脚本方式,传入username和password方式产生用户


#!/bin/shuseradd $1;echo $2|passwd --stdin $1

public static void main(String[] args) {    InputStream in = null;    try{        File file = new File("/");//进入根目录        Process pro = Runtime.getRuntime.exec("./test.sh test testpwd", null, file);        pro.waitFor();        in = pro.getInputStream();        BufferedReader read = new BufferedReader(new InputStreamReader(in));        String result = null;        while((result = read.readLine()) != null)             System.out.println(result);    } catch (Exception e) {        e.printStackTrace();    }
}


0 0
原创粉丝点击