Linked Questions
70 questions linked to/from Python subprocess readlines() hangs
6280
votes
66
answers
5.2m
views
How do I execute a program or call a system command?
How do I call an external command within Python as if I had typed it in a shell or command prompt?
98
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 ...
62
votes
3
answers
77k
views
How to write to stdout AND to log file simultaneously with Popen?
I am using Popen to call a shell script that is continuously writing its stdout and stderr to a log file. Is there any way to simultaneously output the log file continuously (to the screen), or ...
26
votes
8
answers
57k
views
real time subprocess.Popen via stdout and PIPE
I am trying to grab stdout from a subprocess.Popen call and although I am achieving this easily by doing:
cmd = subprocess.Popen('ls -l', shell=True, stdout=PIPE)
for line in cmd.stdout.readlines():
...
38
votes
1
answer
87k
views
Python subprocess .check_call vs .check_output
My python script (python 3.4.3) calls a bash script via subprocess:
import subprocess as sp
res = sp.check_output("bashscript", shell=True)
The bashscript contains the following line:
ssh -MNf ...
30
votes
4
answers
106k
views
Saving stdout from subprocess.Popen to file, plus writing more stuff to the file
I'm writing a python script that uses subprocess.Popen to execute two programs (from compiled C code) which each produce stdout. The script gets that output and saves it to a file. Because the output ...
22
votes
3
answers
9k
views
Python C program subprocess hangs at "for line in iter"
Ok so I'm trying to run a C program from a python script. Currently I'm using a test C program:
#include <stdio.h>
int main() {
while (1) {
printf("2000\n");
sleep(...
26
votes
3
answers
10k
views
Run command and get its stdout, stderr separately in near real time like in a terminal
I am trying to find a way in Python to run other programs in such a way that:
The stdout and stderr of the program being run can be logged
separately.
The stdout and stderr of the program being run ...
19
votes
2
answers
36k
views
Handling tcpdump output in python
Im trying to handle tcpdump output in python.
What I need is to run tcpdump (which captures the packets and gives me information) and read the output and process it.
The problem is that tcpdump ...
9
votes
4
answers
12k
views
Using subprocess with select and pty hangs when capturing output
I'm trying to write a python program that is able to interact with other programs. That means sending stdin and receiving stdout data. I cannot use pexpect (although it definitely inspired some of the ...
9
votes
4
answers
16k
views
Python 3.4.3 subprocess.Popen get output of command without piping?
I am trying to assign the output of a command to a variable without the command thinking that it is being piped. The reason for this is that the command in question gives unformatted text as output if ...
13
votes
1
answer
17k
views
How to properly interact with a process using subprocess module
I'm having problems redirecting stdio of another program using subprocess module. Just reading from stdout results in hanging, and Popen.communicate() works but it closes pipes after reading/writing. ...
11
votes
3
answers
26k
views
Getting output of a process at runtime
I am using a python script to run a process using subprocess.Popen and simultaneously store the output in a text file as well as print it on the console. This is my code:
result = subprocess.Popen(...
21
votes
3
answers
7k
views
Alternatives to Python Popen.communicate() memory limitations?
I have the following chunk of Python code (running v2.7) that results in MemoryError exceptions being thrown when I work with large (several GB) files:
myProcess = Popen(myCmd, shell=True, stdout=...
11
votes
2
answers
8k
views
Realtime output from a shell command in Jupyter notebook
I'm telling jupyter to execute a python script:
!python build_database.py
When executed from the terminal, the python script prints the progress during execution. However, in the jupyter notebook, I ...