Linked Questions
18 questions linked to/from How to write to stdout AND to log file simultaneously with Popen?
0 votes
1 answer
3k views
Print output of subprocess.run AND display it on screen [duplicate]
I am trying to run a shell command via subprocess.run, and I would like to redirect the output to a file, but also display it on stdout at the same time. I have not found a way to do it, is this ...
319 votes
28 answers
311k views
live output from subprocess command
I'm using a python script as a driver for a hydrodynamics code. When it comes time to run the simulation, I use subprocess.Popen to run the code, collect the output from stdout and stderr into a ...
428 votes
11 answers
726k views
Start a background process in Python
I'm trying to port a shell script to the much more readable python version. The original shell script starts several processes (utilities, monitors, etc.) in the background with "&". How can I ...
99 votes
7 answers
111k views
Read streaming input from subprocess.communicate() [duplicate]
I'm using Python's subprocess.communicate() to read stdout from a process that runs for about a minute. How can I print out each line of that process's stdout in a streaming fashion, so that I can ...
92 votes
9 answers
37k views
How to replicate tee behavior in Python when using subprocess?
I'm looking for a Python solution that will allow me to save the output of a command in a file without hiding it from the console. FYI: I'm asking about tee (as the Unix command line utility) and not ...
32 votes
4 answers
46k views
Python subprocess readlines() hangs
The task I try to accomplish is to stream a ruby file and print out the output. (NOTE: I don't want to print out everything at once) main.py from subprocess import Popen, PIPE, STDOUT import pty ...
20 votes
2 answers
12k views
Python subprocess get children's output to file and terminal?
I'm running a script that executes a number of executables by using subprocess.call(cmdArgs,stdout=outf, stderr=errf) when outf/errf is either None or a file descriptor (different files for stdout/...
4 votes
2 answers
13k views
Making Python loggers log all stdout and stderr messages
Using the python logging package, and writing a class Log, I'd like to tee stdout and stderr to a log file : log = Log("log.txt") print "line1" print "line2" print >>sys.stderr, "err1" del log ...
0 votes
1 answer
2k views
Redirect the output of multiple parallel processes to both a log file and stdout without waiting until the processes terminate
I want to redirect the output of (potentially multiple) processes started from within a python script to both stdout and a log file, pretty much like as the unix tool tee does it. A the processes are ...
5 votes
1 answer
718 views
the simplest interface to let subprocess output to both file and stdout/stderr?
I want something have similar effect of cmd > >(tee -a {{ out.log }}) 2> >(tee -a {{ err.log }} >&2) in python subporcess without calling tee. Basically write stdout to both stdout ...
1 vote
0 answers
1k views
How to redirect python output to both python console and a text file in Windows
I have a python script_1 which will be used to call another python script_2 using subprocess. When I do that I can see so many print statements and ouputs on the python console (or cmd). How can I ...
0 votes
1 answer
625 views
Python subprocess delayed in screen buffer while writing print logs in file
Below is my script which calls another script using below example and produces entire output after execution is completed while expectation is that it should produce live output as well as write in ...
1 vote
0 answers
403 views
How to return Ansible ` PLAY RECAP` data to Python caller?
I'm calling my Ansible playbook from a Python script. subprocess.call("ansible-playbook -i hosts my_playbook.yml", shell=True) When this completes there is a PLAY RECAP which includes a ...
1 vote
0 answers
292 views
How to print an output a new console opened using subprocess?
I am trying to achieve a functionality where I can open a new command prompt and run some batch commands. Then redirecting the output to a logfile and console on real time. So I am using wtee.exe (ex ...
0 votes
0 answers
295 views
duplicating output from subprocess popen so it would print and also save into PIPE?
I want to run a subprocess.Popen('echo 1; sleep 1; echo 1', shell=True, stdout=?) in a way I would have the output appear (at run time) and also be able to save it into a PIPE or file. So far I ran ...