title: how do I make my python program to wait for the subprocess to be completed
body: <p>I have a python program which should execute a command line (command line is a psexec command to call a batch file on the remote server)
  I used <strong>popen</strong> to call the command line. The batch on the remote server produces a return code of <strong>0</strong>.
  Now I have to wait for this return code and on the basis of the return code I should continue my program execution.
  I tried to use .wait() or .check_output() but for some reason did not work for me.</p>
  
  <pre><code>cmd = """psexec -u CORPORATE\user1 -p force \\\sgeinteg27 -s cmd /c "C:\\Planview\\Interfaces\\ProjectPlace_Sree\\PP_Run.bat" """
  p = subprocess.Popen(cmd, bufsize=2048, shell=True,
  stdin=subprocess.PIPE, stdout=subprocess.PIPE)
  p.wait()
  print(p.returncode)
  ##The below block should wait until the above command runs completely.
  ##And depending on the return code being ZERO i should continue the rest of 
  ##the execution.
  
  if p.returncode ==0:
      result = tr.test_readXid.readQuery(cert,planning_code)
      print("This is printed depending if the return code is zero")
  </code></pre>
  
  <p><a href="http://i.stack.imgur.com/SXamN.png" rel="nofollow">Here is the EOF the batch file execution and the return code</a>
  Can anybody help me with this ?</p>