1 2 29 30 package com.jcraft.jsch; 31 32 import java.util.*; 33 34 public class ChannelExec extends ChannelSession{ 35 boolean pty=false; 36 String command=""; 37 38 public void setPty(boolean foo){ pty=foo; } 39 public void start() throws JSchException{ 40 try{ 41 Request request; 42 43 if(agent_forwarding){ 44 request=new RequestAgentForwarding(); 45 request.request(session, this); 46 } 47 48 if(xforwading){ 49 request=new RequestX11(); 50 request.request(session, this); 51 } 52 53 if(pty){ 54 request=new RequestPtyReq(); 55 request.request(session, this); 56 } 57 58 if(env!=null){ 59 for(Enumeration _env=env.keys() ; _env.hasMoreElements() ;) { 60 String name=(String )(_env.nextElement()); 61 String value=(String )(env.get(name)); 62 request=new RequestEnv(); 63 ((RequestEnv)request).setEnv(name, value); 64 request.request(session, this); 65 } 66 } 67 68 request=new RequestExec(command); 69 request.request(session, this); 70 } 71 catch(Exception e){ 72 if(e instanceof JSchException) throw (JSchException)e; 73 if(e instanceof Throwable ) 74 throw new JSchException("ChannelExec", (Throwable )e); 75 throw new JSchException("ChannelExec"); 76 } 77 78 if(io.in!=null){ 79 thread=new Thread (this); 80 thread.setName("Exec thread "+session.getHost()); 81 if(session.daemon_thread){ 82 thread.setDaemon(session.daemon_thread); 83 } 84 thread.start(); 85 } 86 } 87 88 public void setCommand(String foo){ command=foo;} 89 public void init(){ 90 io.setInputStream(session.in); 91 io.setOutputStream(session.out); 92 } 93 94 public void setErrStream(java.io.OutputStream out){ 95 setExtOutputStream(out); 96 } 97 public void setErrStream(java.io.OutputStream out, boolean dontclose){ 98 setExtOutputStream(out, dontclose); 99 } 100 public java.io.InputStream getErrStream() throws java.io.IOException { 101 return getExtInputStream(); 102 } 103 } 104 | Popular Tags |