when I start the process like process= Runtime.getRuntime().exec("gnome-terminal");, it starts the execution of the shell, I want to stop the execution of the shell and want to redirect I / O from the process, can anyone tell me how I can do this?
my code is:
public void start_process()
{
try
{
process= Runtime.getRuntime().exec("bash");
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) {
command=tfCmd.getText().toString().trim();
pw.println(command);
execution_command();
}
when I enter any command in the text box and press the execute button, nothing is displayed in my output text box, how can I stop shellexecution and can redirect input and output?
source
share