Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the use of subprocess module in python

Shulou Source: shulou.com Published: 2022-06-03 15:33:53 11月14日 Update

This article mainly shows you "what is the use of the subprocess module in python", the content is simple and clear, and I hope it can help you solve your doubts. Let me lead you to study and learn the article "what is the use of the subprocess module in python".

Description

1. Subprocess is a new module added to Python that allows new processes to be generated and connected to their input/output/error pipes.

And get their return (status) codes.

2. The purpose of this module is to replace several old modules and methods.

Common functions in subprocess module

Function describes the new functions in subprocess.run () Python 3.5. Executes the specified command and waits for the command to complete and returns an instance of the CompletedProcess class that contains the execution results. Subprocess.call () executes the specified command and returns the command execution status, which is similar to os.system (cmd). A new function in subprocess.check_call () Python 2.5. Executes the specified command and returns a status code if it is successful, otherwise an exception is thrown. Its function is equivalent to subprocess.run (..., check=True). A new function in subprocess.check_output () Python 2.7. Executes the specified command and returns the command execution result if the execution status code is 0, otherwise an exception is thrown. Subprocess.getoutput (cmd) receives a command in string format, executes the command, and returns the execution result, which is similar to os.popen (cmd). Read () and commands.getoutput (cmd). Subprocess.getstatusoutput (cmd) executes the cmd command and returns a tuple (command execution status, command execution result output), which functions similar to commands.getstatusoutput (). The above is all the content of the article "what is the use of subprocess module in python". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Commands modules functions states functions results content articles Zhongxin learning help success characters strings examples commonly used methods easy to understand more organized Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Linux macOS Shulou Information Docker