首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

如何用java实现修改unix下一些用户的口令

2011-12-30 
怎么用java实现修改unix下一些用户的口令?我用了以下代码去修改用户的口令,系统只修改为空了。测试时,发现

怎么用java实现修改unix下一些用户的口令?
我用了以下代码去修改用户的口令,系统只修改为空了。测试时,发现使用命令passwd   account后,系统没有返回New   password或Re-enter   new   password字符,因此没有办法传入实际的口令
代码如下:
  public   boolean   chgPassword   (   String   accountname   ,   String   password   )
        {
                String   line   =   null   ;
                boolean   result   =   false   ;
                Process   Process   =   null   ;
                try   {
                        Process   =   Runtime.getRuntime   ().exec   (   "passwd   "   +   accountname   )   ;
                        BufferedReader   in   =   new   BufferedReader   (   new   InputStreamReader   (   Process.getInputStream   ()   )   )   ;
                        OutputStreamWriter   out   =   new   OutputStreamWriter   (   Process.getOutputStream   ()   )   ;
                        while   (   (   line   =   in.readLine   ()   )   !=   null   )   {
                                if   (   line.indexOf   (   "New   password "   )   !=   -1   )   {
                                        out.write   (   "passwd   "   +   password   )   ;
                                        out.flush   ()   ;
                                }   else   if   (   line.indexOf   (   "Re-enter   new   password "   )   !=   -1   )   {
                                        out.write   (   "passwd "   +   password   )   ;
                                        out.flush   ()   ;
                                }   else   if   (   line.indexOf   (   "Passwd   successfully   changed "   )   !=   -1   )   {
                                        result   =   true   ;
                                        out.close   ()   ;
                                        in.close   ()   ;


                                        break   ;
                                }
                                out   =   null   ;
                                in   =   null   ;
                                Process.destroy   ()   ;
                                Process   =   null   ;
                        }
                }
                catch   (   Exception   ex   )   {
                        System.out.println   (   "create   user   occur   Exception: "   +   ex.getMessage   ()   )   ;
                }
                return   result   ;
        }

[解决办法]
没做过,帮顶
[解决办法]
帮忙顶

热点排行
Bad Request.