Python calls external command: subprocess module

Source: Internet
Author: User

Subprocess.call (): Used to execute shell command, the result is printed directly to the terminal

Subprocess.check_call (): Usage is consistent with subprocess.call (), except that it throws an exception when the command executes an error, so that we can capture and process

in [1]: Import Subprocessin [2]: Subprocess.call ('ls' # Executes the LS command directly, the command result is printed to the terminal and returns the status code after the command executes 1. py2. pyout[2]:0In [3]: Subprocess.call ('ls-l', shell=True) # If the command has parameters, you need to add shell=true later, otherwise you will get an error 8-rw-r--r--.1Root root485Oct in  -: * 1. PY-rw-r--r--.1Root root374Oct -  -: - 2. pyout[3]:0

Python calls external command: subprocess module

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.