Guido van Rossum | f06ee5f | 1996-11-27 19:52:01 +0000 | [diff] [blame] | 1 | #! /usr/bin/env python |
Guido van Rossum | 4e62037 | 1995-04-10 11:46:03 +0000 | [diff] [blame] | 2 | |
| 3 | # Remote python client. |
| 4 | # Execute Python commands remotely and send output back. |
| 5 | |
| 6 | import sys |
| 7 | import string |
| 8 | from socket import * |
| 9 | |
| 10 | PORT = 4127 |
| 11 | BUFSIZE = 1024 |
| 12 | |
| 13 | def main(): |
Tim Peters | e6ddc8b | 2004-07-18 05:56:09 +0000 | [diff] [blame] | 14 | if len(sys.argv) < 3: |
Collin Winter | 6f2df4d | 2007-07-17 20:59:35 +0000 | [diff] [blame^] | 15 | print("usage: rpython host command") |
Tim Peters | e6ddc8b | 2004-07-18 05:56:09 +0000 | [diff] [blame] | 16 | sys.exit(2) |
| 17 | host = sys.argv[1] |
| 18 | port = PORT |
| 19 | i = string.find(host, ':') |
| 20 | if i >= 0: |
| 21 | port = string.atoi(port[i+1:]) |
| 22 | host = host[:i] |
| 23 | command = string.join(sys.argv[2:]) |
| 24 | s = socket(AF_INET, SOCK_STREAM) |
| 25 | s.connect((host, port)) |
| 26 | s.send(command) |
| 27 | s.shutdown(1) |
| 28 | reply = '' |
| 29 | while 1: |
| 30 | data = s.recv(BUFSIZE) |
| 31 | if not data: break |
| 32 | reply = reply + data |
Collin Winter | 6f2df4d | 2007-07-17 20:59:35 +0000 | [diff] [blame^] | 33 | print(reply, end=' ') |
Guido van Rossum | 4e62037 | 1995-04-10 11:46:03 +0000 | [diff] [blame] | 34 | |
| 35 | main() |