[New-bugs-announce] [issue42641] Deprecate os.popen() function

STINNER Victor report at bugs.python.org
Mon Dec 14 17:52:43 EST 2020

New submission from STINNER Victor <vstinner at python.org>:

The os.popen() function uses a shell by default which usually leads to shell injection vulnerability.

It also has a weird API:

* closing the file waits until the process completes.
* close() returns a "wait status" (*) not a "returncode"

(*) see https://docs.python.org/dev/library/os.html#os.waitstatus_to_exitcode for the meaning of a "wait status".

IMO the subprocess module provides better and safer alternatives with a clean API. The subprocess module already explains how to replace os.popen() with subprocess:

In Python 2, os.popen() was deprecated since Python 2.6, but Python 3.0 removed the deprecation (commit dcf97b98ec5cad972b3a8b4989001c45da87d0ea, then commit f5a429295d855267c33c5ef110fbf05ee7a3013e extended os.popen() documentation again: bpo-6490).

platform.popen() existed until Python 3.8 (bpo-35345). It was deprecated since Python 3.3 (bpo-11377).


There is also the os.system() function which exposes the libc system() function. Should we deprecate this one as well?

components: Library (Lib)
messages: 383012
nosy: vstinner
priority: normal
severity: normal
status: open
title: Deprecate os.popen() function
versions: Python 3.10

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list