java - JSch Exec output for error -




i need run shell script @ remote machine. using jsch connect remote machine , executing shell script using channelexec. need know how can know, if there error while execution of command.

following code

channelexec channel = (channelexec) session.openchannel("exec");  bufferedreader in = new bufferedreader(new inputstreamreader(channel.getinputstream()));     string command = scriptname; if(parameter != null && !parameter.isempty()){     command += " " + parameter; }  logger.debug("command executed: " + command);               channel.setcommand(command); channel.connect();  //capture output string msg;  stringbuffer output = new stringbuffer(); while ((msg = in.readline()) != null) {     //output = output + msg;     output.append(msg); }  logger.debug("output message = " + output.tostring());  logger.debug("error status --" + channel.getexitstatus());  channel.disconnect(); session.disconnect(); 

start official example "exec" channel, not re-invent wheel:
http://www.jcraft.com/jsch/examples/exec.java.html

to read error, read error stream using channelexec.geterrstream.

or merge output , error streams one:
how 1 stream error stream , input stream when calling script using jsch





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -