title: Run many OS commands in the same OS process with Python 3 to connect DB2 LUW databases
body: <p>I'm trying to create a new process with Python 3 to run more than one command in the "same session" as only one console window was opened. It's something related to DB2 LUW databases where something is stored in memory. I created a file called "winshell.py" with this code:</p>
  
  <pre><code>import sys
  import subprocess
  
  def shell_execute(cmd, filename=""):
      '''
      Executes a command on SO and returns STDOUT and STDERR to a variable.
      If filename is used, then write STDOUT and STDERR to a file.
  
      '''
  
      try:
          output = subprocess.check_output(cmd, shell=True)
          str = output.decode("1252")
          str = str.replace("\r","")    
  
          if filename:
              file = open(filename, "a")
              file.write(str)
              file.close()
              return "Output sent to file: "+filename
          else:
              return str
  
      except subprocess.CalledProcessError as cpe:
          str = cpe.output.decode("1252")
          if filename:
              file = open(filename, "a")
              file.write(str)
              file.close()
          else:
              return str
  
      except Exception as ex:
          format(ex)
  </code></pre>
  
  <p>Then I run from another Python program:</p>
  
  <pre><code>winshell.shell_execute( 'db2 "CONNECT TO AGRIA"', filename )
  winshell.shell_execute( 'db2 "CONNECT RESET"', filename )
  winshell.shell_execute( 'db2 "CONNECT TERMINATE"', filename )
  </code></pre>
  
  <p>The returned code is:</p>
  
  <pre><code>   Database Connection Information
  
   Database server        = DB2/NT64 10.5.0
   SQL authorization ID   = DB2ADMIN
   Local database alias   = AGRIA
  
  SQL1024N  A database connection does not exist.  SQLSTATE=08003
  DB20000I  The TERMINATE command completed successfully.
  </code></pre>
  
  <p>Clearly it runs connect statement with success, but connection is lost just when it finishes. At console prompt these 3 commands works perfectly. </p>
  
  <p>Does anyone knows how to create a session in console as one single process/thread?</p>