(root)/
Python-3.11.7/
Tools/
demo/
rpython.py
       1  #!/usr/bin/env python3
       2  
       3  """
       4  Remote python client.
       5  Execute Python commands remotely and send output back.
       6  """
       7  
       8  import sys
       9  from socket import socket, AF_INET, SOCK_STREAM, SHUT_WR
      10  
      11  PORT = 4127
      12  BUFSIZE = 1024
      13  
      14  def 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:
      22          port = int(host[i+1:])
      23          host = host[:i]
      24      command = ' '.join(sys.argv[2:])
      25      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=' ')
      36  
      37  main()