2010-06-07 93 views
-2

可能重复:
need help about process…如何避免进程的shell执行?

当我开始喜欢process = Runtime.getRuntime().exec("gnome-terminal");一个过程,它开始执行脚本。我想停止shell执行并想从进程中重定向I/O,有人可以告诉我该如何做到这一点?

我的代码是:

public void start_process() 
    { 
     try 
     { 
      process= Runtime.getRuntime().exec("gnome-terminal"); 
      pw= new PrintWriter(process.getOutputStream(),true); 
      br=new BufferedReader(new InputStreamReader(process.getInputStream())); 
      err=new BufferedReader(new InputStreamReader(process.getErrorStream())); 

     } 
     catch (Exception ioe) 
     { 
      System.out.println("IO Exception-> " + ioe); 
     } 


    } 

public void execution_command() 
    { 

     if(check==2) 
     { 
      try 
      { 
       boolean flag=thread.isAlive(); 
       if(flag==true) 
        thread.stop(); 

       Thread.sleep(30); 
       thread = new MyReader(br,tbOutput,err,check); 
       thread.start(); 

      }catch(Exception ex){ 
       JOptionPane.showMessageDialog(null, ex.getMessage()+"1"); 
      } 
     } 
     else 
     { 
      try 
      { 
       Thread.sleep(30); 
       thread = new MyReader(br,tbOutput,err,check); 
       thread.start(); 
       check=2; 

      }catch(Exception ex){ 
       JOptionPane.showMessageDialog(null, ex.getMessage()+"1"); 
      } 

     } 
    } 

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {           
     // TODO add your handling code here: 
     command=tfCmd.getText().toString().trim(); 

     pw.println(command); 

     execution_command(); 

    }  

当我在文本框,然后按输入一些命令来执行按钮,没有任何显示在我的输出textarea的,我怎么能阻止shell执行和输入输出重定向?

+0

重复http://stackoverflow.com/questions/2992801/need-help-about-process - 请不要重新发布相同(或非常相似)的问题。相反,编辑原件。 – 2010-06-07 21:00:30

+0

您已经提问了此问题 – 2010-06-07 21:04:53

回答

0

错误我写了process = Runtime.getRuntime()。exec(“bash”);而不是process = Runtime.getRuntime()。exec(“gnome-terminal”);

+0

请不要将此内容发布为答案,您应该添加这个帖子作为评论。如果您在原始问题中犯了错误,您可以**编辑**。 – 2010-06-08 08:23:25