KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jcraft > jsch > ChannelExec


1 /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2 /*
3 Copyright (c) 2002,2003,2004,2005,2006 ymnk, JCraft,Inc. All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7
8   1. Redistributions of source code must retain the above copyright notice,
9      this list of conditions and the following disclaimer.
10
11   2. Redistributions in binary form must reproduce the above copyright
12      notice, this list of conditions and the following disclaimer in
13      the documentation and/or other materials provided with the distribution.
14
15   3. The names of the authors may not be used to endorse or promote products
16      derived from this software without specific prior written permission.
17
18 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
19 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
21 INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
22 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24 OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */

29
30 package com.jcraft.jsch;
31
32 import java.util.*;
33
34 public class ChannelExec extends ChannelSession{
35   boolean pty=false;
36   String JavaDoc 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 JavaDoc name=(String JavaDoc)(_env.nextElement());
61           String JavaDoc value=(String JavaDoc)(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 JavaDoc e){
72       if(e instanceof JSchException) throw (JSchException)e;
73       if(e instanceof Throwable JavaDoc)
74         throw new JSchException("ChannelExec", (Throwable JavaDoc)e);
75       throw new JSchException("ChannelExec");
76     }
77
78     if(io.in!=null){
79       thread=new Thread JavaDoc(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 JavaDoc 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 JavaDoc out){
95     setExtOutputStream(out);
96   }
97   public void setErrStream(java.io.OutputStream JavaDoc out, boolean dontclose){
98     setExtOutputStream(out, dontclose);
99   }
100   public java.io.InputStream JavaDoc getErrStream() throws java.io.IOException JavaDoc {
101     return getExtInputStream();
102   }
103 }
104
Popular Tags