title: json.decoder.JSONDecodeError: Unterminated string starting at: line 1 column 1 (char 0)
body: <p>This error only happens when I do ipconfig. Dir and mkdir all seem to work!
  First part is the program which would send the commands and the other one, the second one the one which connects to it.</p>
  <pre><code>import socket
  import json
  from sys import exit
  
  class Listener:
      def __init__(self, ip, port):
          listener = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
          listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
          listener.bind((ip, port))
          listener.listen(0)
          print(&quot;[+] Waiting for incoming connections&quot;)
          self.connection, address = listener.accept()
          print(&quot;[+] Connection received from &quot; + str(address))
  
      def reliable_send(self, data):
          json_data = json.dumps(data)
          self.connection.send(json_data.encode())
  
      def reliable_recieve(self):
          json_data = self.connection.recv(1024)
          return json.loads(json_data.decode())
  
      def execute_remotely(self, command):
          self.reliable_send(command)
          if command[0] == &quot;exit&quot;:
              self.connection.close()
              exit()
          return self.reliable_recieve()
  
      def run(self):
          while True:
              command = input(&quot;&gt;&gt; &quot;)
              command = command.split(&quot; &quot;)
              print(command)
              result = self.execute_remotely(command)
              print(result)
  
  my_listener = Listener(&quot;127.0.0.1&quot;, 4444)
  my_listener.run()
  </code></pre>
  <p>Here is the program which connects to it:</p>
  <pre><code>import socket
  import subprocess
  import json
  from sys import exit
  
  class Connect:
      def __init__(self, ip, port):
          self.connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
          self.connection.connect((ip, port))
  
      def reliable_recieve(self):
          json_data = self.connection.recv(1024).decode()
          return json.loads(json_data)
  
      def reliable_send(self, data):
          json_data = json.dumps(data)
          self.connection.send(json_data.encode())
  
      def execute_sys_command(self, command):
          return subprocess.getoutput(command)
  
      def run(self):
          while True:
              command = self.reliable_recieve()
              if command[0] == &quot;exit&quot;:
                  self.connection.close()
                  exit()
              command_result = self.execute_sys_command(command)
              self.reliable_send(command_result)
          self.connection.close()
  
  my_connection = Connect(&quot;127.0.0.1&quot;, 4444)
  my_connection.run()
  </code></pre>
  <p>I don't know why this is happening, it doesn't make sense. All I can think of is that the error is ocurring at the return of the result of the command. I think this because it doesn't have anything different than dir or mkdir such as spaces or the way it's being encoded. So probably it's at the return.</p>