我试图使用JSch在SSH上运行以下命令:
AlgoName -m /tmp/input1.txt -f /tmp/input2.txt > /tmp/output.txt
exitStatus的值为2。该命令不能在SSH上使用Jsch,但它在服务器上成功运行。
我的代码:
ChannelExec channelExec = (ChannelExec) s.openChannel("exec");
channelExec.setCommand(command);
channelExec.connect();
int exitStatus = channelExec.getExitStatus();
channelExec.disconnect();发布于 2018-06-13 08:18:15
我试图运行的算法是用Perl编写的,实际上,当我通过JSCH执行远程SSH命令时,用于运行命令的用户配置文件没有加载,因此环境变量也没有加载。
解决方案是在运行命令时加载配置文件,如下所示:
bash -l -c 'AlgoName -m /tmp/input1.txt -f /tmp/input2.txt > /tmp/output.txt'https://stackoverflow.com/questions/50819604
复制相似问题