开发者

How to avoid shell execution of a Process? [duplicate]

开发者 https://www.devze.com 2023-01-02 09:54 出处:网络
This question already has an answer here: Closed 12 years ago. Possible Duplicate: need help about process…
This question already has an answer here: Closed 12 years ago.

Possible Duplicate:

need help about process…

When I start a process like process = Runtime.getRuntime().exec("gnome-terminal");, it starts shell execution. I want to stop shell execution and want to redirect I/O from process, can anybody tell how I can do this?

My code is:

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();

    }    

When I enter some command in textfield and press execute button, nothing is displayed on my output textarea, how I can stop shell execution and redirect input and output?


by mistake i wrote process= Runtime.getRuntime().exec("bash"); instead of process= Runtime.getRuntime().exec("gnome-terminal");

0

精彩评论

暂无评论...
验证码 换一张
取 消