title: Can not print output of python script that run with subprocess
body: <p>I try to test server and want print it output on end of the test here</p>
  
  <pre><code>class TestHandler(TestCase):
  
      def setUp(self):
          cmd = [
              'python', '-m', 'server',
              '-f', write_to_path,
              '--debug'
          ]
          self.server = Popen(cmd, universal_newlines=True, cwd=root_dir_path,
                              stdout=PIPE, stderr=PIPE)
  
          # also tried this, did not help
          # cmd = [
          #     'python -m server --debug -f ' + write_to_path
          # ]
          # self.server = Popen(cmd, shell=True, universal_newlines=True, cwd=root_dir_path,
          #                     stdout=PIPE, stderr=PIPE)
  
      def tearDown(self):
          try:
              outs, errs = self.server.communicate(timeout=2)
              print(outs, errs)
          except TimeoutExpired:
              print("kill")
              self.server.kill()
              outs, errs = self.server.communicate()
              print(outs, errs) # empty output here
  
      def testWordWithoutParent(self):
          pass
  </code></pre>
  
  <p>When I run it, stdout and err is empty, but server code was executed (I tested it main function in server/__main__.py  with pdb)</p>
  
  <pre><code> ~/Documents/LINGUALEO/lingualeo2anki $ python -m unittest
  .kill
  
  .
  ----------------------------------------------------------------------
  Ran 2 tests in 2.006s
  
  OK
  </code></pre>
  
  <p><a href="https://github.com/BjornMelgaard/lingualeo2anki/blob/rewrite/tests/test.py#L19" rel="nofollow noreferrer">Source here</a></p>
  
  <p>I tried a lot of answers on stackowerflow almost 3 hours and none helped, I gave up.</p>