Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to log non-python warnings

I have .py script which starts java application from shell using os.system. There are always a lot of WARNING messages after starting java apperas. I want just to write them in log file without printing them in console. I dont get how to catch them... Is it possible to do using logging lib?

like image 882
stickmann Avatar asked Feb 03 '26 19:02

stickmann


1 Answers

something like the below

import subprocess
p = subprocess.Popen(["java", "<java args goes here>"], stdout=subprocess.PIPE)
out, err = p.communicate() # out || err will hold the data you are looking for - you can write them to python logger
like image 73
balderman Avatar answered Feb 05 '26 08:02

balderman