Primary
os.popen() ⚬|Documentation|1st|20251021151358-00-⌔
os — Miscellaneous operating system interfaces — Python 3 documentation#os.popen
os.popen(cmd, mode='r', buffering=-1)Open a pipe to or from command cmd. The return value is an open file object connected to the pipe, which can be read or written depending on whether mode is
'r'(default) or'w'. The buffering argument have the same meaning as the corresponding argument to the built-inopen()function. The returned file object reads or writes text strings rather than bytes.The
closemethod returnsNoneif the subprocess exited successfully, or the subprocess’s return code if there was an error. On POSIX systems, if the return code is positive it represents the return value of the process left-shifted by one byte. If the return code is negative, the process was terminated by the signal given by the negated value of the return code. (For example, the return value might be- signal.SIGKILLif the subprocess was killed.) On Windows systems, the return value contains the signed integer return code from the child process.On Unix,
waitstatus_to_exitcode()can be used to convert theclosemethod result (exit status) into an exit code if it is notNone. On Windows, theclosemethod result is directly the exit code (orNone).This is implemented using
subprocess.Popen; see that class’s documentation for more powerful ways to manage and communicate with subprocesses.Availability: not WASI, not Android, not iOS.
Note: The Python UTF-8 Mode affects encodings used for cmd and pipe contents.
popen()is a simple wrapper aroundsubprocess.Popen. Usesubprocess.Popenorsubprocess.run()to control options like encodings.Soft deprecated since version 3.14: The
subprocessmodule is recommended instead.Printed 2026-06-28.
(echo:: @ ᯤ)
Link to original
Secondary
• • •