blob: 11f72cb3dd26a61b9e1b1896970f52c3cebfa501 [file] [log] [blame]
Georg Brandl856898b2010-12-30 22:11:50 +00001#!/usr/bin/env python3
Georg Brandl7fafbc92010-12-30 21:33:07 +00002
Georg Brandl856898b2010-12-30 22:11:50 +00003"""
4Remote python client.
5Execute Python commands remotely and send output back.
6"""
Georg Brandl7fafbc92010-12-30 21:33:07 +00007
8import sys
9from socket import socket, AF_INET, SOCK_STREAM, SHUT_WR
10
11PORT = 4127
12BUFSIZE = 1024
13
14def main():
15 if len(sys.argv) < 3:
16 print("usage: rpython host command")
17 sys.exit(2)
18 host = sys.argv[1]
19 port = PORT
20 i = host.find(':')
21 if i >= 0:
周家未d59b6622019-04-22 21:28:57 +080022 port = int(host[i+1:])
Georg Brandl7fafbc92010-12-30 21:33:07 +000023 host = host[:i]
24 command = ' '.join(sys.argv[2:])
Serhiy Storchaka172bb392019-03-30 08:33:02 +020025 with socket(AF_INET, SOCK_STREAM) as s:
26 s.connect((host, port))
27 s.send(command.encode())
28 s.shutdown(SHUT_WR)
29 reply = b''
30 while True:
31 data = s.recv(BUFSIZE)
32 if not data:
33 break
34 reply += data
35 print(reply.decode(), end=' ')
Georg Brandl7fafbc92010-12-30 21:33:07 +000036
37main()