當我開始像process= Runtime.getRuntime().exec("gnome-terminal");
這樣的進程時,它開始執行shell,我想停止shell執行並想從進程中重定向I/O,任何人都可以告訴我該怎麼做?需要關於進程的幫助
我的代碼是:
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) {
// TODO add your handling code here:
command=tfCmd.getText().toString().trim();
pw.println(command);
execution_command();
}
當我在文本框輸入一些命令,並按下執行鍵,沒事就我的輸出textarea的顯示,我怎麼能阻止shellexecution並且可以重定向輸入和輸出?