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