How to avoid shell execution of a Process? [duplicate]
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");
精彩评论