Runtime rt= Runtime.getRuntime() ;
      Process p=rt.exec("add ur command line here") ;
      p.waitFor() ;
      int return_value =p.exitValue() ;

解决方案 »

  1.   

    gary_shi(Gary Shi)兄:
    怎么没有反应啊。
      

  2.   

    我运行了我的程序,具体如下int staff_id;
    String passwd;
    int    count=0;
    staff_id=Integer.parseInt(request.getParameter("acc_nbr"));
    passwd=request.getParameter("passwd");
          Runtime rt= Runtime.getRuntime() ;
          Process p=rt.exec("/www/htdocs/netoffice/check "+staff_id+" "+passwd) ;
          p.waitFor() ;
          int return_value =p.exitValue() ;
      if (return_value!=0)
      {
      System.out.println("密码错误!");
      return;
      }可是什么都没有,既没有进入正常页面,也没有出现"密码错误"的提示。我的操作系统是Linux;
      

  3.   

    ¿ÉÄÜÊÇÒòΪÄãµÄC³ÌÐòÊä³ö£¬ÊÔÊÔÏÂÃæµÄ´úÂë
    int staff_id;
    String passwd;
    int    count=0;
    staff_id=Integer.parseInt(request.getParameter("acc_nbr"));
    passwd=request.getParameter("passwd");
          Runtime rt= Runtime.getRuntime() ;
          Process p=rt.exec("/www/htdocs/netoffice/check "+staff_id+" "+passwd) ;
          
          CheckStream csin = new CheckStream(p.getInputStream());
          CheckStream cserr = new CheckStream(proInstall.getErrorStream());
          csin.start();
          cserr.start();
          
          p.waitFor() ;
          proInstall.destroy();
          
          int return_value =p.exitValue() ;
      if (return_value!=0)
      {
      System.out.println("ÃÜÂë´íÎó!");
      return;
      }
      /**
       * Êä³ö¿ØÖÆ̨ÐÅÏ¢µÄÏß³Ì
       */
      class CheckStream extends Thread{    BufferedReader bufferedReader;
        String lineRead = "";    /**
         * Constructor needs an InputStream to form an anonymous
         * InputStreamReader which is used to create a BufferedReader
         * for reading the stream.
         */
        CheckStream(InputStream is){
          this.bufferedReader = new BufferedReader(new InputStreamReader(is));
        }    public void run(){
          try{
            while ((lineRead = bufferedReader.readLine()) != null){
              showProcessInfo(lineRead);
            }
          }catch(Exception ioe){
          }
        }
      }
      

  4.   

    对不起,出现乱码!
    可能是由于你的C程序输出的控制台信息,试试下面的代码int staff_id;
    String passwd;
    int    count=0;
    staff_id=Integer.parseInt(request.getParameter("acc_nbr"));
    passwd=request.getParameter("passwd");
          Runtime rt= Runtime.getRuntime() ;
          Process p=rt.exec("/www/htdocs/netoffice/check "+staff_id+" "+passwd) ;
          
          CheckStream csin = new CheckStream(p.getInputStream());
          CheckStream cserr = new CheckStream(proInstall.getErrorStream());
          csin.start();
          cserr.start();
          
          p.waitFor() ;
          proInstall.destroy();
          
          int return_value =p.exitValue() ;
      if (return_value!=0)
      {
      System.out.println("ÃÜÂë´íÎó!");
      return;
      }
      /**
       * 输出控制台信息的线程
       */
      class CheckStream extends Thread{    BufferedReader bufferedReader;
        String lineRead = "";    /**
         * Constructor needs an InputStream to form an anonymous
         * InputStreamReader which is used to create a BufferedReader
         * for reading the stream.
         */
        CheckStream(InputStream is){
          this.bufferedReader = new BufferedReader(new InputStreamReader(is));
        }    public void run(){
          try{
            while ((lineRead = bufferedReader.readLine()) != null){
              showProcessInfo(lineRead);
            }
          }catch(Exception ioe){
          }
        }
      }
      

  5.   

    org.apache.jasper.JasperException: Unable to compile class for JSP/usr/local/jakarta-tomcat/work/localhost_8080%2Fnetoffice/_0002foffice_0002ejspoffice_jsp_37.java:59: Class BufferedReader not found.
                        BufferedReader bufferedReader;
                                                     ^
    /usr/local/jakarta-tomcat/work/localhost_8080%2Fnetoffice/_0002foffice_0002ejspoffice_jsp_37.java:67: Class InputStream not found.
                        CheckStream(InputStream is){
                        ^
    /usr/local/jakarta-tomcat/work/localhost_8080%2Fnetoffice/_0002foffice_0002ejspoffice_jsp_37.java:68: Class BufferedReader not found.
                          this.bufferedReader = new BufferedReader(new InputStreamReader(is));
                                                    ^
    /usr/local/jakarta-tomcat/work/localhost_8080%2Fnetoffice/_0002foffice_0002ejspoffice_jsp_37.java:73: Class BufferedReader not found in void run().
                            while ((lineRead = bufferedReader.readLine()) != null){
                                                                      ^
    /usr/local/jakarta-tomcat/work/localhost_8080%2Fnetoffice/_0002foffice_0002ejspoffice_jsp_37.java:74: Method showProcessInfo(java.lang.String) not found in local class CheckStream (_0002foffice_0002ejspoffice_jsp_37. 1$CheckStream).
                              showProcessInfo(lineRead);
                                             ^
    /usr/local/jakarta-tomcat/work/localhost_8080%2Fnetoffice/_0002foffice_0002ejspoffice_jsp_37.java:95: Class InputStream not found in new.
                          CheckStream csin = new CheckStream(p.getInputStream());
                                             ^
    /usr/local/jakarta-tomcat/work/localhost_8080%2Fnetoffice/_0002foffice_0002ejspoffice_jsp_37.java:96: Undefined variable or class name: proInstall
                          CheckStream cserr = new CheckStream(proInstall.getErrorStream());
                                                              ^
    /usr/local/jakarta-tomcat/work/localhost_8080%2Fnetoffice/_0002foffice_0002ejspoffice_jsp_37.java:101: Undefined variable or class name: proInstall
                          proInstall.destroy();
                          
    错误更多了
      

  6.   

    CheckStream类需要编译后放到/WEB-INF/classes下,
    java.io.BufferedReader需要引用
    proInstall 改为 p
    showProcessInfo() 去掉
    你的问题最可能的原因就是由于你的C程序输出的控制台信息!
      

  7.   

    请参考
    http://www.powerba.com/develop/web/java/article/20010630001.htm