~ubuntu-branches/ubuntu/trusty/jsch/trusty-proposed

« back to all changes in this revision

Viewing changes to src/com/jcraft/jsch/ChannelExec.java

  • Committer: Bazaar Package Importer
  • Author(s): Jerry Haltom
  • Date: 2005-01-13 16:07:20 UTC
  • Revision ID: james.westby@ubuntu.com-20050113160720-7ohwkg0rbifgq3lu
Tags: upstream-0.1.19
ImportĀ upstreamĀ versionĀ 0.1.19

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*-mode:java; c-basic-offset:2; -*- */
 
2
/*
 
3
Copyright (c) 2002,2003,2004 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.net.*;
 
33
 
 
34
public class ChannelExec extends ChannelSession{
 
35
  boolean xforwading=false;
 
36
  String command="";
 
37
  /*
 
38
  ChannelExec(){
 
39
    super();
 
40
    type="session".getBytes();
 
41
    io=new IO();
 
42
  }
 
43
  */
 
44
  public void setXForwarding(boolean foo){
 
45
    xforwading=true;
 
46
  }
 
47
  public void start(){
 
48
    try{
 
49
      Request request;
 
50
      if(xforwading){
 
51
        request=new RequestX11();
 
52
        request.request(session, this);
 
53
      }
 
54
      request=new RequestExec(command);
 
55
      //((RequestExec)request).setCommand(command);
 
56
      request.request(session, this);
 
57
    }
 
58
    catch(Exception e){
 
59
    }
 
60
    //(new Thread(this)).start();
 
61
    thread=new Thread(this);
 
62
    ((Thread)thread).start();
 
63
  }
 
64
  public void setCommand(String foo){ command=foo;}
 
65
  public void init(){
 
66
    io.setInputStream(session.in);
 
67
    io.setOutputStream(session.out);
 
68
  }
 
69
  public void finalize() throws java.lang.Throwable{
 
70
    ((Thread)thread).interrupt();
 
71
    thread=null;
 
72
    super.finalize();
 
73
  }
 
74
  public void run(){
 
75
//System.out.println(this+":run >");
 
76
    thread=this;
 
77
    Buffer buf=new Buffer();
 
78
//    Buffer buf=new Buffer(lmpsize);
 
79
    Packet packet=new Packet(buf);
 
80
    int i=0;
 
81
    try{
 
82
      while(isConnected() &&
 
83
            thread!=null && 
 
84
            io!=null && 
 
85
            io.in!=null){
 
86
        i=io.in.read(buf.buffer, 14, buf.buffer.length-14);
 
87
        if(i==0)continue;
 
88
        if(i==-1){
 
89
          eof();
 
90
          break;
 
91
        }
 
92
        if(close)break;
 
93
        packet.reset();
 
94
        buf.putByte((byte)Session.SSH_MSG_CHANNEL_DATA);
 
95
        buf.putInt(recipient);
 
96
        buf.putInt(i);
 
97
        buf.skip(i);
 
98
        session.write(packet, this, i);
 
99
      }
 
100
    }
 
101
    catch(Exception e){
 
102
      //System.out.println("# ChannelExec.run");
 
103
      //e.printStackTrace();
 
104
    }
 
105
    thread=null;
 
106
//System.out.println(this+":run <");
 
107
  }
 
108
 
 
109
  public void setErrStream(java.io.OutputStream out){
 
110
    setExtOutputStream(out);
 
111
  }
 
112
  public java.io.InputStream getErrStream() throws java.io.IOException {
 
113
    return getExtInputStream();
 
114
  }
 
115
}