title: How to run multiple commands via python socket
body: <p>I have problem with my code, I want to run a commands on my virual machines via sockets. I found problem with multiple tasks,commands. For example if I open Excel my socket server has been freezed and I cannot run another command via cmd before I close excel application manually. </p>
  
  <p>What I should change in code to open multiple applications in one time on my virtual machine? (for example. I want to open in one time four xlsx files)</p>
  
  <p>Server.py</p>
  
  <pre class="lang-py prettyprint-override"><code>import socket
  import subprocess
  import os
  from threading import Thread
  
  
  def check_ping(hostname):
      response = os.system("ping " + hostname)
      # and then check the response...
      if response == 0:
          pingstatus = "Network Active"
      else:
          pingstatus = "Network Error"
  
      return(pingstatus)
  
  def run_path(path):
      response = os.system(path)
      # and then check the response..
      return('ok')
  
  
  
  def Main():
      host = "localhost"
      port = 5000
  
      mySocket = socket.socket()
      mySocket.bind((host,port))
  
      mySocket.listen(1)
      conn, addr = mySocket.accept()
      print ("Connection from: " + str(addr))
      while True:
              data = conn.recv(1024).decode()
              if not data:
                      break
              #print ("from connected  user: " + str(data))
  
              #data = str(data)
              #hostname = data.replace('ping ', '')
  
              print ("sending: " + str(data))
              #print(hostname)
              conn.send(data.encode())
              if 'ping' in str(data):
                  hostname = data.replace('ping ', '')
                  pingstatus = check_ping(hostname)
                  print(pingstatus)
              elif 'open' in str(data):
                  path = str(data).replace('open ', '')
  
                  run_path(path)
  
  
  
  
  
      conn.close()
  
  if __name__ == '__main__':
      Main()
  </code></pre>
  
  <p>Client.py</p>
  
  <pre class="lang-py prettyprint-override"><code>import socket
  
  def Main():
          host = '127.0.0.1'
          port = 5000
  
          mySocket = socket.socket()
          mySocket.connect((host,port))
  
          message = input(" -&gt; ")
  
          while message != 'q':
                  mySocket.send(message.encode())
                  data = mySocket.recv(1024).decode()
  
                  print ('Received from server: ' + data)
  
                  message = input(" -&gt; ")
  
          mySocket.close()
  
  if __name__ == '__main__':
      Main()
  </code></pre>