简体   繁体   中英

ExitStatus 2 when I run a command over SSH with JSCH

I'm trying to run the following command over SSH with JSch :

AlgoName -m /tmp/input1.txt -f /tmp/input2.txt > /tmp/output.txt

The value of exitStatus is 2 . The command does not work over SSH with Jsch but it run successfully on the server.

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.

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'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM