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 ')
|