Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8098837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:12:05+00:00 2026-06-05T22:12:05+00:00

Im trying to SSH from Java to a server and run multiple commands. the

  • 0

Im trying to SSH from Java to a server and run multiple commands. the commands seem to work ok but I am not getting the results back in Java that I wanted.

Here is my code snippet

        final Command cmd = session.exec("cd /app/t/backo/bin && ls -all && pwd && . setDBLApp && sudo -E -u deploy ./runDBLApp && sudo -E -u deploy ./nightlyDBL -type host ");

        System.out.println(IOUtils.readFully(cmd.getInputStream()).toString());
        cmd.join(30, TimeUnit.SECONDS);
        System.out.println("\n** exit status: " + cmd.getExitStatus());

Here is what I see for output. I think its something to do with LocalWindow sizing but I cannot figure out how to fix it. This only happens (or seems to) when I use ssh commands that would have lots of screen output

This is a small snippet I get 100 or so lines of this

14:56:48.957 [reader] INFO  n.s.s.c.c.direct.SessionChannel - Received window adjustment for 2097152 bytes
14:56:48.957 [reader] DEBUG n.s.s.c.channel.Window$Remote - Increasing by 2097152 up to 2097152
14:56:48.957 [reader] DEBUG net.schmizz.concurrent.Promise - Setting <<chan#0 / chanreq for exec>> to `SOME`
14:56:48.963 [reader] DEBUG n.s.s.c.channel.Window$Local - Consuming by 4096 down to 2093056
14:56:48.964 [reader] DEBUG n.s.s.c.channel.Window$Local - Consuming by 1002 down to 2092054
14:56:48.964 [reader] DEBUG n.s.s.c.channel.Window$Local - Consuming by 23 down to 2092031
14:56:49.090 [reader] DEBUG n.s.s.c.channel.Window$Local - Consuming by 141 down to 2091890
14:56:49.120 [reader] DEBUG n.s.s.c.channel.Window$Local - Consuming by 267 down to 2091623
14:56:49.230 [reader] DEBUG n.s.s.c.channel.Window$Local - Consuming by 309 down to 2091314
14:56:49.531 [reader] DEBUG n.s.s.c.channel.Window$Local - Consuming by 308 down to 2091006
14:56:49.532 [reader] DEBUG n.s.s.c.channel.Window$Local - Consuming by 306 down to 2090700

What I want to see is the screen output from the ssh commands which might be verbose

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T22:12:07+00:00Added an answer on June 5, 2026 at 10:12 pm

    You are right in thinking this probably has to do with window sizing. The local window sshj keeps for output coming from the server could have filled up. The default rule is for it to be expanded when you create space in the buffer by reading from the stdout/stderr streams provided by the API i.e. channel.getInputStream()/channel.getErrorStream()

    You have two options:

    • Keep draining the stdout and stderr streams while the command executes. Based on your snippet you actually are reading from stdout but not stderr. You could multiplex the reads from the 2 streams using the available() method on java.io.InputStream, which is implemented.

    • Set sessionChannel.setAutoExpand(true) but note that this means, no matter how much output is produced the local window will keep expanding even if you are not draining the stdout/stderr streams by reading from them. So this has the potential to cause high memory consumption.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to run some unix commands from my java code. I am
I'm trying to run a command on a remote server via SSH from a
How do I run multiple commands in SSH using Java runtime? the command: ssh
I'm trying to connect and fetching source from a SSH server with using PuTTY,
In the following command i am trying to ssh commands and execute the multiple
Been back and forth on this recently. Trying to attach a SSH tunnel from
I'm trying to start a test server via ssh but it always dies once
I'm trying to automate an SSH connection to a server from a windows box.
Scenerio: I'd like to run commands on remote machines from a Java program over
I am trying to use SSH to connect to my own server from an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.