2010-03-12 06:53:45 +08:00
|
|
|
#! /usr/bin/env python3
|
1995-04-10 19:46:03 +08:00
|
|
|
|
|
|
|
# Remote python client.
|
|
|
|
# Execute Python commands remotely and send output back.
|
|
|
|
|
|
|
|
import sys
|
2010-12-31 05:33:07 +08:00
|
|
|
from socket import socket, AF_INET, SOCK_STREAM, SHUT_WR
|
1995-04-10 19:46:03 +08:00
|
|
|
|
|
|
|
PORT = 4127
|
|
|
|
BUFSIZE = 1024
|
|
|
|
|
|
|
|
def main():
|
2004-07-18 13:56:09 +08:00
|
|
|
if len(sys.argv) < 3:
|
2007-07-18 04:59:35 +08:00
|
|
|
print("usage: rpython host command")
|
2004-07-18 13:56:09 +08:00
|
|
|
sys.exit(2)
|
|
|
|
host = sys.argv[1]
|
|
|
|
port = PORT
|
2010-12-31 05:33:07 +08:00
|
|
|
i = host.find(':')
|
2004-07-18 13:56:09 +08:00
|
|
|
if i >= 0:
|
2010-12-31 05:33:07 +08:00
|
|
|
port = int(port[i+1:])
|
2004-07-18 13:56:09 +08:00
|
|
|
host = host[:i]
|
2010-12-31 05:33:07 +08:00
|
|
|
command = ' '.join(sys.argv[2:])
|
2004-07-18 13:56:09 +08:00
|
|
|
s = socket(AF_INET, SOCK_STREAM)
|
|
|
|
s.connect((host, port))
|
2010-12-31 05:33:07 +08:00
|
|
|
s.send(command.encode())
|
|
|
|
s.shutdown(SHUT_WR)
|
|
|
|
reply = b''
|
|
|
|
while True:
|
2004-07-18 13:56:09 +08:00
|
|
|
data = s.recv(BUFSIZE)
|
2010-12-31 05:33:07 +08:00
|
|
|
if not data:
|
|
|
|
break
|
|
|
|
reply += data
|
|
|
|
print(reply.decode(), end=' ')
|
|
|
|
s.close()
|
1995-04-10 19:46:03 +08:00
|
|
|
|
|
|
|
main()
|