Skip to content

System.out redirect not released #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
EasyG0ing1 opened this issue Apr 4, 2025 · 0 comments
Open

System.out redirect not released #56

EasyG0ing1 opened this issue Apr 4, 2025 · 0 comments

Comments

@EasyG0ing1
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant