title: Python : Execute several commands in CMD in single instance
body: <p>I am trying to call several "blocking" .bat files from my python program. First thing I need to do is change the directory that the CMD is opened. After I have the CMD pointing to the desired location I will call two bat files. I want them to execute sequentially.</p>
  
  <pre><code>def launchAdminConsole():    
      print('Going to launch admin console')
      changeDir = 'cd dir1\\dir2\\bin \n 1.bat \n 2.bat'
      os.system("start /wait cmd /c {"+changeDir+"}")
      print("Admin Console launced")
  </code></pre>
  
  <p><a href="https://stackoverflow.com/questions/11615455/python-start-new-command-prompt-on-windows-and-wait-for-it-finish-exit">According to this question</a> using the <code>/wait</code> should make the command prompt wait but for me, it just pops up and goes away so I am not sure if the bat file is executed or not. </p>
  
  <p>Also I am not sure if I have formed the command line code correctly. I googled about how to execute several commands in a single instance of cmd from python but none of the results helped me much so I took a guess on my own and did the above code. </p>
  
  <p>I need the command prompt to open and run the two bat files and then give the control back to python. I do not need to fetch the output of the bat files or something I just need to know if the two files are executed or not. As I said before they are all blocking bat files so if run correctly the command prompt will not be able to close so quickly. I hope you guys got my requirement else comment below I will explain more.</p>
  
  <p>Edit : 
  Updated my code as follows</p>
  
  <pre><code>def launchAdminConsole2():
      print('Going to launch admin console')
      changeDir = 'cd dir1\\dir2\\bin'
      runOnce1 = '1.bat'
      runOnce2 = '2.bat'
      p = subprocess.Popen(changeDir,shell=True)
      p.wait()
      print(p.returncode)
      p = subprocess.call([changeDir, runOnce, runOnce1])
      p.wait()
      print("Admin Console launced")
  </code></pre>
  
  <p>The return code for the change directory returns <code>0</code> but it is saying that <code>1.bat</code> is not found. I am sure that if the directory has changed that file will be present in the given location.</p>
  
  <p>The error is </p>
  
  <pre><code> File "C:\Users\nirma\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 304, in call
      with Popen(*popenargs, **kwargs) as p:
    File "C:\Users\nirma\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 756, in __init__
      restore_signals, start_new_session)
    File "C:\Users\nirma\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 1155, in _execute_child
      startupinfo)
  FileNotFoundError: [WinError 2] The system cannot find the file specified
  </code></pre>