通過調用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();
}
}