当我开始喜欢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执行和输入输出重定向?
重复http://stackoverflow.com/questions/2992801/need-help-about-process - 请不要重新发布相同(或非常相似)的问题。相反,编辑原件。 – 2010-06-07 21:00:30
您已经提问了此问题 – 2010-06-07 21:04:53