TA的每日心情 | 开心 2021-12-13 21:45 |
---|
签到天数: 15 天 [LV.4]偶尔看看III
|
通过调用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(); }
复制代码
|
|