I have two different python files (Example: a.py & b.py). I'm calling b.py in a.py using subprocess in the following way:
try:
p = sp.Popen(
["python", "b.py", "--user_config", json.dumps(user_conf)],
stdin=sp.PIPE,
stdout=sp.PIPE,
stderr=sp.PIPE,
encoding='cp1252'
)
stdout, stderr = p.communicate()
except Exception as e:
print(e)
else:
print("Script continues...")
FIRST ISSUE
b.py uses python logging package and it can print out info, warning or error, when it's invoked using logging.info(), logging.warning() or logging.error().
However, all the logging.info(), logging.warning() and logging.error() is being spawned under stderr and not under stdout when I'm expecting it to spawn in the following manner:
- stdout -
logging.info()&logging.warning() - stderr -
logging.error()
SECOND ISSUE
When the error occurs, I want the Exception to catch it but it's not doing it, and the script continues to run.
What am I doing wrong here? Is there any other way to handle such issues?