23def main(user_host, cmd, fail_errorlevel):
24 ssh_cmd = [
'ssh',
'-oConnectTimeout=15',
'-oBatchMode=yes', user_host,
25 '(' + cmd +
') & if not errorlevel %s echo %s' % (
26 fail_errorlevel, SENTINEL)]
29 print(
'Original command:\n%s\nFull command:\n%s' % (
30 cmd,
' '.join([repr(s)
for s
in ssh_cmd])), file=sys.stderr)
31 proc = subprocess.Popen(ssh_cmd, stdout=subprocess.PIPE)
32 for line
in iter(proc.stdout.readline,
''):
33 stripped = line.strip()
34 if stripped == SENTINEL:
40 if proc.returncode != 0:
41 sys.exit(proc.returncode)