通过调用shell脚本方式,传入username和password方式产生用户
#!/bin/sh
useradd $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(); }
}