Python Standard output redirection

Source: Internet
Author: User

1. Python calls other programs

Os.system () method

The system () function in the OS module makes it easy to run other programs or scripts. Its function prototypes are:
Os.system (command)
command to execute commands similar to those entered in the Windows CMD window.

If you want to pass parameters to a program or script, you can use a space-delimited program and multiple parameters.

Subprocess.call () Method Example demonstrates:

Open Notepad:

1 Import os2 Os.system (' Notepad ')

Or

1 Import subprocess2 subprocess.call (' Notepad ')

Let's look at the following code:

1 Import os2 Os.system (R ' "D:\Program Files (x86) \netease\cloudmusic\cloudmusic.exe")

This code will start the NetEase cloud music, the effect and we enter "D:\Program Files (x86) \netease\cloudmusic\cloudmusic.exe" effect in the cmd window. Note that the string contains spaces, so there is R '.

The following code can also implement the same functionality:

1 Import subprocess2 Subprocess.call ("D:\Program Files (x86) \netease\cloudmusic\cloudmusic.exe")

2. Python output redirection

3. Call cmd (Windows) or shell (Linux) output redirection

4. Function result Redirection

Python Standard output redirection

Related Article

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.