Well, it’s a convenient and robust way. I’d probably point new people to subprocess.run these days. Everything in one box! It relegates subprocess.Popen to the less common situations. Cheers, Cameron Simpson cs@cskk.id.au Answer from cameron on discuss.python.org
🌐
Tutorialspoint
tutorialspoint.com › python › os_popen.htm
Python os.popen() Method
import os, sys # using command mkdir a = "mkdir nwdir" b = os.popen(a,"r",1) print (b) When we run above program, it will create a directory named "nwdir" with read mode. ... In this example, we are executing the "ls" command which lists the ...
🌐
Stack Abuse
stackabuse.com › pythons-os-and-subprocess-popen-commands
Python's os and subprocess Popen Commands
November 9, 2017 - Thus, for example "rb" will produce a readable binary file object. In order to retrieve the exit code of the command executed, you must use the close() method of the file object. The bufsize parameter tells popen how much data to buffer, and can assume one of the following values: ... This ...
Discussions

Please help me understand how subprocess.popen works
Hello Python Masters…I am a beginner…Please help me understand how this code works: PyLocScript = r"C:\Phyton\PyApps\CSV_values_analyze.py" CsvLink = r"C:\Phyton\PyApps\sample.csv" PartNo = "LM3339" area = 45 xcor = 1.5… More on discuss.python.org
🌐 discuss.python.org
3
0
November 4, 2022
How to get output from subprocess.Popen along with visible execution?
I am trying to get the output by running below dummy code for my project - #test.py import time for x in range(5): print(i) time.sleep(1) This is test2.py import subprocess cmd = "python3 test.py" process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=true, text=true) ... More on discuss.python.org
🌐 discuss.python.org
6
1
July 22, 2024
Using python with subprocess Popen - Stack Overflow
I am struggling to use subprocesses with python. Here is my task: Start an api via the command line (this should be no different than running any argument on the command line) Verify my API has ... More on stackoverflow.com
🌐 stackoverflow.com
How to use subprocess popen Python - Stack Overflow
Many OS functions that the Python ... for example. But that has nothing to do with whether they are included in the stdlib or not. I believe the UNIX philosophy of "Unix was not designed to stop its users from doing stupid things, as that would also stop them from doing clever things." also applies in large parts to Python. 2012-09-26T18:01:58.097Z+00:00 ... In the recent Python version, subprocess has a big change. It offers a brand-new class Popen to handle ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Python
docs.python.org › 3 › library › subprocess.html
subprocess — Subprocess management
1 week ago - On Windows Subsystem for Linux and QEMU User Emulation, Popen constructor using os.posix_spawn() no longer raise an exception on errors like missing program, but the child process fails with a non-zero returncode. Exceptions raised in the child process, before the new program has started to execute, will be re-raised in the parent. The most common exception raised is OSError. This occurs, for example, when trying to execute a non-existent file.
🌐
Codecademy
codecademy.com › article › python-subprocess-tutorial-master-run-and-popen-commands-with-examples
Python Subprocess Tutorial: Master run() and Popen() Commands (with Examples) | Codecademy
Hello from Python! ... 'more' is a shell command that paginates input. Here, it is run with shell=True so Windows recognizes it. ... process.communicate() sends the input string and waits for process completion, returning the output. The print(output) displays what the subprocess returned. ... Popen() also enables chaining commands by connecting their inputs and outputs using subprocess.PIPE. In the example below, we are piping findstr and sort on Windows:
🌐
Squash
squash.io › tutorial-subprocess-popen-in-python
Tutorial: Subprocess Popen in Python - Squash Labs
November 2, 2023 - A simple guide on how to use the subprocess.Popen function in Python.
🌐
Real Python
realpython.com › python-subprocess
The subprocess Module: Wrapping Programs With Python – Real Python
January 18, 2025 - Some documented changes have happened as late as 3.8. The examples in this article were tested with Python 3.10.4, but you only need 3.8+ to follow along with this tutorial. Most of your interaction with the Python subprocess module will be via the run() function. This blocking function will start a process and wait until the new process exits before moving on. The documentation recommends using run() for all cases that it can handle. For edge cases where you need more control, the Popen ...
🌐
DataCamp
datacamp.com › tutorial › python-subprocess
An Introduction to Python Subprocess: Basics and Examples | DataCamp
September 12, 2025 - In this example, the Popen class is used to create two child processes, one for the ls command and one for the grep command. The stdout of the ls command is connected to the stdin of the grep command using subprocess.PIPE, which creates a pipe between the two processes.
Find elsewhere
🌐
Pythonspot
pythonspot.com › python-subprocess
Python Subprocess — Tutorial with Examples
If you start notepad.exe as a windowed app then python will not get the output. The MSDOS command similar to "cat" is "type". process = Popen(['type', 'test.py'], stdout=PIPE, stderr=PIPE)
🌐
Educative
educative.io › answers › how-to-perform-command-line-interactions-using-ospopen-in-python
How to perform command line interactions using os.popen in Python
Here’s a code example that uses deprecated and insecure practices, demonstrating the potential risks of command injection in Python applications: ... In this example, the os.popen() function relies on the shell to execute the command.
🌐
Medium
medium.com › @techclaw › python-popen-understanding-subprocess-management-in-python-83cbc309e714
Python Popen: Understanding Subprocess Management in Python | by TechClaw | Medium
August 8, 2023 - To run a basic command using Python Popen, we start by importing the subprocess module and then use the Popen constructor to create a new process. For example:
🌐
Python Module of the Week
pymotw.com › 2 › subprocess
subprocess – Work with additional processes - Python Module of the Week
Reading from stderr works the same as with stdout. Passing PIPE tells Popen to attach to the channel, and communicate() reads all of the data from it before returning. $ python -u subprocess_popen3.py popen3: pass through: 'through stdin to stdout' stderr : 'to stderr\n'
🌐
Linux find Examples
queirozf.com › entries › python-3-subprocess-examples
Python 3 Subprocess Examples
November 26, 2022 - Method asyncio.create_subprocess_exec() works much the same way as Popen() but calling wait() and communicate() on the returned objects does not block the processor, so the Python interpreter can be used in other things while the external subprocess doesn't return.
🌐
Reddit
reddit.com › r/learnpython › how does the os.popen work()?
r/learnpython on Reddit: how does the os.popen work()?
June 19, 2017 -

The link I found: https://www.tutorialspoint.com/python/os_popen.htm, tells me that os.popen works like a pipe, but my book gives me a very confusing example:
1) open('something.py')

which is because we need an open stream. next it gives:

  h = os.popen('type something.py').read()

At this point, I'm not getting, if os.popen() acts like a pipe('|' on the terminal), then how is this supposed to be pipeing to the stream opened. and what is it piping?

🌐
Linux Mint Forums
forums.linuxmint.com › board index › interests › programming & development
[Solved] Question about using Popen in Python - Linux Mint Forums
September 6, 2021 - Yes, communicate() tends to work, but it might be a matter of the password-requesting application in his case not in fact reading the password from stdin. sudo for example does not unless instructed to via -S; it otherwise communicates directly with the terminal device. But this for example works fine: ... import subprocess proc = subprocess.Popen('sudo -S whoami'.split(), stdin=subprocess.PIPE, stderr=subprocess.PIPE) proc.communicate(b'password\n')
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-subprocess-module
Python subprocess module - GeeksforGeeks
2 weeks ago - ... import subprocess res = subprocess.run(["python", "--version"], capture_output=True, text=True) print("Output:", res.stdout) print("Return Code:", res.returncode) ... Popen starts a new process and allows interaction with it while it is running.
🌐
Better Stack
betterstack.com › community › guides › scaling-python › python-subprocess
An Introduction to Python Subprocess | Better Stack Community
This example shows how Popen gives you more flexibility than run(). The subprocess begins running immediately, and your main Python program continues executing in parallel.