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 8964673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:38:30+00:00 2026-06-15T16:38:30+00:00

currently I am trying to run some commands on a ssh-server using the Ganymed-SSH2-Library

  • 0

currently I am trying to run some commands on a ssh-server using the Ganymed-SSH2-Library for Java. Because I also need to call a perl script, i can’t use Session.execCommand();, because it will just run “normal” unix-commands (or is this wrong?). Instead I need to use a pseudoterminal.

If I run the following code it hangs:

session = con.openSession();
session.requestPTY("vt220");
session.execCommand("/bin/bash");
session.getStdin().write("echo test".getBytes());
int b = 1;
InputStream is = new StreamGobbler(session.getStdout());
while ((b = is.read()) != -1) {
    System.out.print((char)b);
}
System.out.println("finished");

will result in the following output (censored USERNAME and HOST):

echo testUSERNAME@HOST:~

# echo test

but the code will hang at this point and never reach System.out.println("finished");

The connection-build up works perfectly, if i run the following code, it works:

session = con.openSession();
session.execCommand("ls");
BufferedReader reader = new BufferedReader(new InputStreamReader(new StreamGobbler(session.getStdout())));
String line = reader.readLine();
while (line != null) {
    line = reader.readLine();
    System.out.println(line);
}
System.out.println("finished");

Anyone knows, where the problem is? Some time ago I tried this with Jsch (another SSH-Lib for Java) but it has the same problems.

Thanks in advance 🙂

  • 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-15T16:38:31+00:00Added an answer on June 15, 2026 at 4:38 pm

    I guess that the problem has not come from JSch and Ganymed.
    How about the following?

    session.getStdin().write("echo test; exit".getBytes());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying to run a certain procedure (sql 2005) in VB6, passing some
I am trying to do run a bulk deletion using parameterized queries. Currently, I
Im currently trying to downlaod a audio track from a WCF, i need some
I am trying to send some commands from a server to about 50 clients
I have been trying to run some java programs from a bash script in
I am trying to run some Java EE examples. Ant is suggesting: Perhaps JAVA_HOME
I'm trying to compile some .less files using django-pipeline . When I run collectstatic
I'm currently trying to run a LINQ query over a MS SQL database. This
i am currently trying to run a web crawler through the terminal. it compiles
Currently I'm trying to run this powershell script: Param ( $websiteName, $physicalPath ) import-module

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.