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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:30:36+00:00 2026-06-11T20:30:36+00:00

I’m using Primefaces’ Terminal component and JSch to ssh to a remote desktop. With

  • 0

I’m using Primefaces’ Terminal component and JSch to ssh to a remote desktop. With the exec channel the execution takes too much time as both session and channel closes at each command and I didn’t manage to avaid that. So I changed the channel to shell and now I’m trying to “redirect” standard input/outputsteam. Here’s what my code looks like :

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;

@ManagedBean
@SessionScoped
public class TerminalController implements Serializable{  

     public TerminalController(){
     jsch=new JSch();
     InputStream in=null;
     PrintStream out=System.out;
try{
                      session=jsch.getSession(user, ip, port);
                      session.setConfig("StrictHostKeyChecking", "no");
                        session.setPassword(passwd);
                        session.connect();
                       channel=session.openChannel("shell");    
                       channel.setInputStream(in);
                       channel.setOutputStream(out);
                       channel.connect();
}catch(Exception ee){
                      System.out.println(ee);
} }
    public String handleCommand(String command, String[] params) {  
     command=command+StringUtils.join(params," ");

                   in=IOUtils.toInputStream(command);
                  String result=out.toString();
                   out.flush();
                    return result;}

I know it’s a mess, I’m still a beginner in java.
Another problem I thought about is that in the conversion from iostream to string I may lose the enter button function ! I’m waiting for you suggestions, solutions and pieces of advice.

  • 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-11T20:30:37+00:00Added an answer on June 11, 2026 at 8:30 pm

    Setting the in variable has no effect on the channel, and calling out.toString() will not get you any results.

    You need to write the command (with its parameters) to the channel, and then read the output from there. Also, don’t use the setInputStream or setOutputStream methods (they are good if you have existing streams from which to read or to which to write, which you don’t).

    public class TerminalController implements Serializable{  
    
        BufferedReader fromChannel;
        PrintWriter toChannel;
        Channel channel;
        Session session;
    
         public TerminalController(){
            jsch=new JSch();
            try {
                session=jsch.getSession(user, ip, port);
                session.setConfig("StrictHostKeyChecking", "no");
                session.setPassword(passwd);
                session.connect();
                channel = session.openChannel("shell");    
                InputStream inStream = channel.getInputStream();
                fromChannel = new BufferedReader(new InputStreamReader(inStream, "UTF-8"));
                OutputStream outStream = channel.getOutputStream();
                toChannel = new PrintWriter(new OutputStreamWriter(outStream, "UTF-8"));
                channel.connect();
            } catch(Exception ee) {
                ee.printStackTrace();
            }
        }
    
        public String handleCommand(String command, String[] params) {  
             command = command + StringUtils.join(params," ");
             toChannel.println(command);
             StringBuilder result = new StringBuilder();
             while(true) {
                String line = fromChannel.readLine();
                result.append(line);
                if(looksLikePrompt(line))
                   return result.toString();
                result.append("\n");
             }
        }
    }
    

    The hard part is actually knowing when the output from the remote command is finished, and you need to return (this is in the looksLikePrompt method I don’t know how to write).

    I’m not sure that the CommandHandler principle of Primeface’s terminal component is the right design for creating an interactive terminal, where the terminal shouldn’t need to know when a command is finished. What happens when a command needs more input?

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I don't have much knowledge about the IPv6 protocol, so sorry if the question

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.