title: How can I use commands when connecting computers through socket?
body: <p>I set up a python script to connect two computers with sockets and am trying to run commands from terminal. The script will hopefully run the commands on the host onto the client but it doesnt recognize any commands. My code for the server is </p>
  
  <pre><code>import socket
  
  HOST = '0.0.0.0'
  PORT = 12345
  
  server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  server_socket.bind((HOST, PORT))
  
  server_socket.listen(5)
  print("\n[*] Listening on port " +str(PORT)+ ", waiting for connexions.")
  
  
  client_socket, (client_ip, client_port) = server_socket.accept()
  print("[*] Client " +client_ip+ " connected.\n")
  
  
  while True:
      try:
          command = input(client_ip+ "&gt;")
          if(len(command.split()) != 0):
              client_socket.send(bytes(command, 'utf-8'))
          else:
              continue
      except(EOFError):
              print("Invalid input, type 'help' to get a list of implemented commands.\n")
              continue
  
      if(command == "quit"):
          break
  
      data = client_socket.recv(1024)
      print((data + b"\n"))
  
  client_socket.close()
  
  </code></pre>
  
  <p>and the client is</p>
  
  <pre><code>import socket
  import subprocess, os
  
  HOST = ''
  PORT = 12345
  
  connexion_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  connexion_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  connexion_socket.connect((HOST, PORT))
  print('\n[*] Connected to " +HOST+ " "on port" +str(PORT+) ".\n"')
  
  while True:
  
      command = str(connexion_socket.recv(1024))
      split_command = command.split()
      print('Received command : ' +command)
  
      if command == 'quit':
          break
  
      if(command.split()[0] == 'cd'):
          if len(command.split()) == 1:
              connexion_socket.send((os.getcwd()))
          elif len(command.split()) == 2:
              try:
                  os.chdir(command.split()[1])
                  connexion_socket.send(('Changed Directory to' + os.getcwd()))
              except:
                  connexion_socket.send(str.encode('No such directory : ' +os.getcwd()))
  
      else:
  
          proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
  
          stdout_value = proc.stdout.read() + proc.stderr.read()
          print(str(stdout_value) + '\n')
  
          if(stdout_value != ''):
              connexion_socket.send(stdout_value)
          else:
              connexion_socket.send(command+ ' does not return anything')
  
  </code></pre>
  
  <p>Whenever I try to run a command like 'ipconfig' or 'cd' i get the error</p>
  
  <p>"is not recognized as an internal or external command,\r\noperable program or batch file.\r\n\n"</p>
  
  <p>Any help is appreciated, Thanks!</p>