7from __future__
import print_function
20SENTINEL =
'win_ssh_cmd remote command successful'
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)
47if __name__ ==
'__main__':
49 print(
'USAGE: %s <user@host> <cmd shell string> [<fail errorlevel>]' %
50 sys.argv[0], file=sys.stderr)
52 arg_fail_errorlevel = 1
if len(sys.argv) < 4
else sys.argv[3]
53 main(sys.argv[1], sys.argv[2], arg_fail_errorlevel)
def print(*args, **kwargs)
def main(user_host, cmd, fail_errorlevel)
static SkString join(const CommandLineFlags::StringArray &)