Jsch SSH server calling a Linux command or script minor issue

Source: Internet
Author: User
Tags ssh server

The code is as follows:

     Public Static BooleanExecshell (String command, string user, String passwd, String host)throwsjschexception, IOException {Connect (user, passwd, host); BufferedReader Reader=NULL; BooleanFlag =true; Channel Channel=NULL; String CharSet= "UTF-8"; Try {              //execute the linux commandChannel = Session.openchannel ("exec");             ((channelexec) channel). SetCommand (command);             ( (CHANNELEXEC) channel). Seterrstream (System.err);             Channel.connect (); InputStream in=Channel.getinputstream (); Reader=NewBufferedReader (NewInputStreamReader (In, Charset.forname (Charset))); String buf=NULL;  while((buf = Reader.readline ())! =NULL) {log.info (BUF); }                         }Catch(Exception e) {e.printstacktrace (); }finally{reader.close ();                   Channel.disconnect ();          Session.disconnect (); }        returnFlag; }

Here is a problem, if you use the method in red font to output the system error when executing the linux command or SH file, this will cause a problem, that is, the method of using log4j is invalid, Subsequent log.info and log in other classes will be invalidated, and eventually Tomcat's catalina.out log is stopped forever .... So when using, be sure to comment out Oh ~ or do not OH ~ Use the following reader read Linux output information on the line Oh ~

Jsch SSH server calling a Linux command or script minor issue

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.