Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hi, I have a question. I use SSHJ execute the command "nohup Java jar - server - Xms1g - Xmx1g - XX: XX: + UseG1GC - + UnlockExperimentalVMOptions - XX: G1NewSizePercent = 20 -XX:G1MaxNewSizePercent=30 -XX:+DisableExplicitGC /data/deploy/jar/nut-helloworld.jar --spring.profiles.active=dev >> /data/deploy/jar/nut-helloworld.log 2> &1&", returns a status code of 0, but it does not take effect. The same command that I wrote in the script worked when the script was executed #868

Open
wzd-hash opened this issue Jun 12, 2023 · 1 comment

Comments

@wzd-hash
Copy link

public static Result execCommand(SSHClient ssh, String command,boolean isSudo){
Result r = new Result();
Session session = null;
try {
log.info("执行命令:" + command);
session = ssh.startSession();
Map<PTYMode, Integer> emptyMap = new HashMap<>();
session.allocatePTY("xterm", 80, 24, 0, 0, emptyMap );
command = getCommand(command, isSudo);
final Session.Command cmd = session.exec(command);
cmd.join(300, TimeUnit.SECONDS);
String runLog = IOUtils.readFully(cmd.getInputStream()).toString();
String errorLog = IOUtils.readFully(cmd.getErrorStream()).toString();
Integer exitStatus = cmd.getExitStatus();
r = handleResult(exitStatus, runLog, errorLog, command);
} catch (ConnectionException e) {
r.setStatus(-1);
r.handleErrorLog(e.getMessage());
r.setIsSuccess(false);
} catch (IOException e) {
r.setStatus(-1);
r.handleErrorLog(e.getMessage());
r.setIsSuccess(false);
} finally {
closeSession(session);
}

    log.info("\n** exit status: " + r.getStatus() + " 执行成功与否:" + r.getIsSuccess());
    return r;
}
@XSWClevo
Copy link

找到解决方案了吗,我这边执行相关的操作也是这样子

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants