How to get jsch shell command output in String

前端 未结 3 412
醉梦人生
醉梦人生 2020-12-01 13:18

I am using a JSCH -SSH library to execute command in \"shell\" channel, but unable to find a way to do 2 things:-

1) How to find whether the command is completely ex

3条回答
  •  一整个雨季
    2020-12-01 13:35

    For 2) u can use ByteArrayOutputStream

    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    channel.setOutputStream(baos);
    

    and then create new string from new String(baos.toByteArray())

    For 1 have you tried to use 2>&1 at the end of your command?

    String commandToRun = "ls /tmp/*.log 2>&1 \n";
    

提交回复
热议问题