Skip to content

Commit

Permalink
Fix error code with SSH
Browse files Browse the repository at this point in the history
The echo previously introduced mess up the return code.

Fix #82
  • Loading branch information
tbarbette committed Dec 18, 2024
1 parent c381884 commit 6131918
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion npf/executor/sshexecutor.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ def exec(self, cmd, bin_paths : List[str] = None,
#First echo the pid of the shell, so it can be recovered and killed in case of kill from another script
#Then launch the pre-command (goes to the right folder)
#Then the user command, wrapped with sudo and/or bash if needed
ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command("echo $$;"+ pre + cmd + " ; echo '' ;")
final_command = "echo $$;"+ pre + cmd + " ; retval=$? ; echo '' ; exit $retval"
ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command(final_command)
if stdin is not None:
ssh_stdin.write(stdin)
channels = [ssh_stdout, ssh_stderr]
Expand Down
6 changes: 3 additions & 3 deletions npf/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def _parallel_exec(param: RemoteParameters):
else:
if param.autokill is not None:
if param.options.debug:
print("[DEBUG] Script %s finished, killing all other scripts" % param.name)
print(f"[DEBUG] Script {param.name} finished with exit code {c}, killing all other scripts")
param.event.c.acquire()
param.autokill.value = param.autokill.value - 1
v = param.autokill.value
Expand All @@ -115,11 +115,11 @@ def _parallel_exec(param: RemoteParameters):
elif pid == -1:
#Keyboard interrupt
if param.options.debug:
print("[DEBUG] Script %s stopped through keyboard interrupt." % param.name)
print(f"[DEBUG] Script {param.name} stopped through keyboard interrupt.")
Test.killall(param.queue, param.event)
else:
if param.options.debug:
print("[DEBUG] Script %s finished, autokill=false so it will not terminate the other scripts." % param.name)
print(f"[DEBUG] Script {param.name} finished with exit code {c}, autokill=false so it will not terminate the other scripts." % param.name)
if pid == -1:
return -1, o, e, c, param.script
return True, o, e, c, param.script
Expand Down

0 comments on commit 6131918

Please sign in to comment.