[英]ExitStatus 2 when I run a command over SSH with JSCH
I'm trying to run the following command over SSH with JSch : 我正在尝试使用JSch通过SSH运行以下命令:
AlgoName -m /tmp/input1.txt -f /tmp/input2.txt > /tmp/output.txt
算法名称-m /tmp/input1.txt -f /tmp/input2.txt> /tmp/output.txt
The value of exitStatus is 2 . exitStatus的值为2 。 The command does not work over SSH with Jsch but it run successfully on the server.
该命令无法通过Jsch在SSH上运行,但可以在服务器上成功运行。
My code: 我的代码:
ChannelExec channelExec = (ChannelExec) s.openChannel("exec");
channelExec.setCommand(command);
channelExec.connect();
int exitStatus = channelExec.getExitStatus();
channelExec.disconnect();
The algorithm I'm trying to run is written in Perl, actually when I execute the remote SSH command via JSCH, the user profile used to run the command are not loaded, so the environment variables are not loaded either. 我尝试运行的算法是用Perl编写的,实际上,当我通过JSCH执行远程SSH命令时,用于运行该命令的用户配置文件未加载,因此环境变量也未加载。
The solution is to load the profile when I run the command, like this: 解决方案是在运行命令时加载配置文件,如下所示:
bash -l -c 'AlgoName -m /tmp/input1.txt -f /tmp/input2.txt > /tmp/output.txt'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.