Use the OS. system function in Python to run other programs

Source: Internet
Author: User

Run other programs

In python, you can easily use the OS module to run other scripts or programs, so that you can directly use other scripts or functions provided by the program in the script, you do not have to write code to implement this function again. To better control running processes, you can use the functions in the win32process module. If you want to further control the process, you can use the ctype module to directly call the function in kernel32.dll.

1. Use the OS. system function to run other programs

The system () function in the OS module can easily run other programs or scripts. The function prototype is as follows.

OS. System (command)


The parameter meanings are as follows.

The command to be executed is equivalent to the command entered in the Windows cmd window. If you want to pass parameters to a program or script, you can use spaces to separate the program and multiple parameters.

The following example uses the OS. System () function to open the Notepad program of the system.

    

>>> Import OS
# Use the OS. System () function to open the Notepad program
>>> OS. System ('notepad ')
0 # the return value after notepad is disabled
# Upload the python.txt file to the notebook and open it.
>>> OS. System ('notepad python.txt ')

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.