]>
Commit | Line | Data |
---|---|---|
4710c53d | 1 | #! /usr/bin/env python\r |
2 | \r | |
3 | # Remote python client.\r | |
4 | # Execute Python commands remotely and send output back.\r | |
5 | \r | |
6 | import sys\r | |
7 | import string\r | |
8 | from socket import *\r | |
9 | \r | |
10 | PORT = 4127\r | |
11 | BUFSIZE = 1024\r | |
12 | \r | |
13 | def main():\r | |
14 | if len(sys.argv) < 3:\r | |
15 | print "usage: rpython host command"\r | |
16 | sys.exit(2)\r | |
17 | host = sys.argv[1]\r | |
18 | port = PORT\r | |
19 | i = string.find(host, ':')\r | |
20 | if i >= 0:\r | |
21 | port = string.atoi(port[i+1:])\r | |
22 | host = host[:i]\r | |
23 | command = string.join(sys.argv[2:])\r | |
24 | s = socket(AF_INET, SOCK_STREAM)\r | |
25 | s.connect((host, port))\r | |
26 | s.send(command)\r | |
27 | s.shutdown(1)\r | |
28 | reply = ''\r | |
29 | while 1:\r | |
30 | data = s.recv(BUFSIZE)\r | |
31 | if not data: break\r | |
32 | reply = reply + data\r | |
33 | print reply,\r | |
34 | \r | |
35 | main()\r |