Skip to content

System.out redirect not released #56

@EasyG0ing1

Description

@EasyG0ing1

Hello,

Consider this code:

            JSch    jsch    = new JSch();
            Session session = jsch.getSession(USER, HOST, 22);
            session.setPassword(PASSWORD);
            session.setConfig("StrictHostKeyChecking", "no");
            session.connect();
            ChannelExec channel = (ChannelExec) session.openChannel("exec");
            channel.setCommand(COMMAND);
            channel.setErrStream(System.err);
            channel.setInputStream(null);
            channel.setOutputStream(System.out);
            channel.connect();
            while (!channel.isClosed()) {
                sleep(100, TimeUnit.MILLISECONDS);
            }
            channel.disconnect();
            session.disconnect();

After that code runs, when I try to do System.out.println() it doesn't work. It's like the library is not releasing System.out.

I did a little digging into the classes and found this in the IO class:

  /*
  public void finalize() throws Throwable{
    try{
      if(in!=null) in.close();
    }
    catch(Exception ee){}
    try{
      if(out!=null) out.close();
    }
    catch(Exception ee){}
    try{
      if(out_ext!=null) out_ext.close();
    }
    catch(Exception ee){}
  }
  */

And was wondering if that code being commented out has anything to do with it?

I found a work around by creating a custom OutputStream object then redirecting the channel to that and then in there I have it print to System.out. Doing it that way I don't ever lose the ability to print to console.

Do you have any idea why this is happening?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions