Linked Questions
75 questions linked to/from read subprocess stdout line by line
10 votes
6 answers
60k views
python subprocess output to list or file
I want to run the following bash command in Python 3: ls -l I know that I can do the following: from subprocess import call call(['ls', '-l']) How do I save this output to a file, or put it into ...
15 votes
4 answers
38k views
sys.stdin.readlines() hangs Python script
Everytime I'm executing my Python script, it appears to hang on this line: lines = sys.stdin.readlines() What should I do to fix/avoid this? EDIT Here's what I'm doing with lines: lines = sys....
14 votes
3 answers
18k views
Python Run a daemon sub-process & read stdout
I need to run a program and gather its output to stdout. This program (socat) needs to run in the background for the duration of the python script. Socat sits in dameon mode once it's run, but first ...
16 votes
2 answers
25k views
returncode of Popen object is None after the process is terminated
I'm running a process with the use of Popen. I need to wait for the process to terminate. I'm checking that the process have terminated through the returncode. When returncode is different from None ...
11 votes
6 answers
6k views
How to get subprocess' stdout data asynchronously?
I wrote a simple python script for my application and predefined some fast commands like make etc. I've written a function for running system commands (linux): def runCommand(commandLine): print(...
10 votes
3 answers
19k views
Asynchronously read stdout from subprocess.Popen
I am running a sub-program using subprocess.popen. When I start my Python program from the command window (cmd.exe), the program writes some info and dates in the window as the program evolves. When ...
8 votes
3 answers
17k views
subprocess popen.communicate() vs. stdin.write() and stdout.read()
I have noticed two different behaviors with two approaches that should have result in the same outcome. The goal - to execute an external program using subprocess module, send some data and read the ...
4 votes
5 answers
3k views
Getting return information from another python script
I'm on linux, and I have one python script that I want to call from another python script. I don't want to import it as a module (for a layer of security, and now for an academic exercise because I ...
0 votes
5 answers
8k views
Wrapping bash scripts in python
I just found this great wget wrapper and I'd like to rewrite it as a python script using the subprocess module. However it turns out to be quite tricky giving me all sorts of errors. download() { ...
7 votes
1 answer
7k views
How to return stdout from long running process with subprocess and Popen?
I'm using a pretty basic setup with subprocess.Popen() and directing stdout to a variable which I later return to a different part of my python script. Here is my basic Popen code: process = ...
0 votes
2 answers
8k views
Stop sys.stdout from writing to a text file
I am using python sys to save my stdout to a text file. sys.stdout=open('OLSYield.txt','w') However I only want a portion of the stdout to go to the text. How do I stop writing to txt file and ...
4 votes
4 answers
5k views
Python/Batch: Use Python to press any key to continue
I am using a python script to automate a process involving batch files. These are batch files that are used for other applications and I am not allowed to edit them. At the end of the batch file, it ...
0 votes
3 answers
5k views
Multi-threading in Python and shell
I have a shell script called "nn.sh" which takes an ip address in a local network and SSH into that ip and then continuously read off some data from that ip and appends the results to a file called "...
3 votes
1 answer
4k views
Python capture stdout from subprocess line by line
I've read many of the questions related to this and learned a lot but I still haven't been able to solve my problem. I'm building a wxPython app that runs a c++ executable and displays the stdout from ...
0 votes
2 answers
5k views
How to Grab IP address from ping in Python
I am currently using python 2.7 and will need to ping windows and linux. I want to create a function that will return the IP address from a ping within a python script. I currently have this function ...