blob: e9657203df8457c7339cc0c6bdccd937bae5f6fd [file] [log] [blame]
Georg Brandl7fafbc92010-12-30 21:33:07 +00001#! /usr/bin/env python3
2
3# Remote python client.
4# Execute Python commands remotely and send output back.
5
6import sys
7from socket import socket, AF_INET, SOCK_STREAM, SHUT_WR
8
9PORT = 4127
10BUFSIZE = 1024
11
12def main():
13 if len(sys.argv) < 3:
14 print("usage: rpython host command")
15 sys.exit(2)
16 host = sys.argv[1]
17 port = PORT
18 i = host.find(':')
19 if i >= 0:
20 port = int(port[i+1:])
21 host = host[:i]
22 command = ' '.join(sys.argv[2:])
23 s = socket(AF_INET, SOCK_STREAM)
24 s.connect((host, port))
25 s.send(command.encode())
26 s.shutdown(SHUT_WR)
27 reply = b''
28 while True:
29 data = s.recv(BUFSIZE)
30 if not data:
31 break
32 reply += data
33 print(reply.decode(), end=' ')
34 s.close()
35
36main()