jsch


JSCH read from input stream hangs from time to time


I'm using jsch-0.1.53.
In order to execute a command and return it's output, I wrote the next block of code:
#Override
public String executeAndGetOutput(CheckPointSSHConnection connection, String command) throws IOException , JSchException{
logger.debug("Executing command \"" + command + "\"");
StringBuilder retVal = new StringBuilder();
ChannelExec channel = null;
InputStream in=null;
InputStream errStream=null;
try {
Session session = connection.getSession();
channel = (ChannelExec) session.openChannel("exec");//only shell
in = channel.getInputStream();
errStream = channel.getErrStream();
channel.setCommand(command);
channel.connect(10000);
String errInStr = StringUtils.toString(errStream);
String inStr = StringUtils.toString(in);
return inStr+errInStr;
} finally {
IOUtils.close(in);
IOUtils.close(errStream);
if (channel != null) {
try {
channel.disconnect();
} catch (Throwable throwable) {
logger.warn("An exception occured while trying to close ssh chanel. Message:",
throwable.getMessage());
}
}
}
}
The problem is that from time to time, reading the errStream just hangs and blocking the thread.
Can someone please tell me what I'm doing wrong?
The command that I'm executing is load_indicators --add -a detect -i /tmp/sample_file.csv , it's Checkpoint CLI

Related Links

how to delete local file using jsch after file is sent to remote SFTP server directory
com.jcraft.jsch.JSchException: Auth fail error
Creating a new file in SSH enabled system using JSCH
How to interact with the script after its execution using Jsch
java jsch -executing multiple unix commands
How to get one stream from error stream and input stream when calling a script using JSCH
SFTP using jschexception verify false sometimes fails
how to increase the jsch buffer size?
The cipher 'aes256-cbc' is required, but it is not available
How to pause/resume procedure while/after upload file by ChannelSftp
jsch + running multiple command in shell after SU and then close channal
NGit/Nsch Generating SSH Keypair (c# Jgit)
Extract userInfo from JSCH stream
Running a Shell Script using java ( process Builder ) with a specific unix user
Java jsch and resuming file upload after interruption?
How to pass a variable through channel in Jsch?

Categories

HOME
xamarin
winforms
client
cloud
netbeans
fluentd
appx
bookshelf.js
yarn
twitter-bootstrap-4
packages
upload
midi
spring-xd
google-cloud-spanner
zend-framework3
pugjs
http-status-code-504
google-pagespeed
visjs
ml
apache-commons-io
url-scheme
windowbuilder
gitignore
libssl
sql-server-2012-express
.net-4.0
avcapturesession
rotational-matrices
mapdb
plsql-psp
stacked
serverside-rendering
elasticsearch-plugin
optix
fedex
ibpy
isbn
qcombobox
executenonquery
scorm
wso2carbon
logfiles
outlook-2013
togetherjs
statsd
brightcove
jxcore
typed-lambda-calculus
font-size
capacity
pdfclown
dwscript
root-framework
setuptools
probability-density
phishing
measures
skobbler-maps
gstreamer-0.10
markojs
essence
whois
iad
pervasive-sql
rtbkit
spim
sdhc
comobject
interrupted-exception
notify
truevault
javafx-webengine
bundles
eventual-consistency
interface-orientation
lcs
enterprisedb
delphi-6
mhtml
chuck
libstdc++
bluepill
word-processor
online-compilation
ohm
code-cleanup
punbb
hirefire
vdsp
hamachi
appender
recent-documents
telerik-scheduler
createwindow
jquery-ui-droppable
preference
virtual-functions
zend-decorators
windows-live-messenger

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App