Python Access logging of another program ran in subprocess

MRAB python at mrabarnett.plus.com
Sun Jun 26 13:35:57 EDT 2016


On 2016-06-26 17:38, p.infante413 at gmail.com wrote:
> Hello, I'm currently running another Python program (prog2.py) in my program via subprocess.
>
> input_args = ['python', '/path/to/prog2.py'] + self.chosen_args
> file = open("logfile.txt",'w')
> self.process = Popen((input_args), stdout=file)
>
> However, the logs that prog2.py contains still show at the terminal since logs are not covered in the stdout module and printed in the terminal, also, the logfile.txt is empty. Is there a way I can access those logs while in prog1.py? I can't modify prog2.py since it is not mine. I'm stuck here for days now, any tips or help will do.
>
The output you're seeing might be going to stderr, not stdout.




More information about the Python-list mailing list