Quantcast
Viewing all articles
Browse latest Browse all 4

Answer by CHebs2018 for How to capture terminal output as execution proceeds?

import subprocess,shlex
command = 'python mesh.py'
workingdirectory = 'C:users/Account/Desktop'
try:
    process = subprocess.Popen(shlex.split(command), stdout=subprocess.PIPE,
                                     stderr=subprocess.PIPE, shell=True, cwd=workingdirectory)

    stdout, stderr = process.communicate()

     if stderr.decode('utf-8') == "":
        with open(outputlog.txt, 'w'):
             file.write(stdout.decode('utf-8'))
     else:
          with open(errorlog.txt,'w') as file:
              file.write(stderr.decode('utf-8'))

Create 2 empty text files named outputlog and errorlog in the working directory.

Use Shlex to build your command, Popen for IPC.


Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>