python implementation of running other programs
- 2020-06-12 09:49:27
- OfStack
python implementation of running other programs
Here provide two implementation methods, 1. os. system() function and use ShellExecute function to run other programs and implementation code, you can refer to the following,
1 Use the os. system() function to run other programs
Open the system notepad program
>>>import os
>>> os.system('notepad')
0
>>> os.system('notepad python.txt')
0
Use the ShellExecute function to run other programs
>>>import win32api
>>> win32api.ShellExecute(0,'open','notepad.exe','','',0)
42
>>> win32api.ShellExecute(0,'open','notepad.exe','','',1)
42
>>> win32api.ShellExecute(0,'open','notepad.exe','python.txt','',1)
42
>>> win32api.ShellExecute(0,'open','http://www.python.org','python.txt','',1)
42
>>> win32api.ShellExecute(0,'open','E:\\python\\work\\Demo.mp3','','',1)
42
>>> win32api.ShellExecute(0,'open','E:\\python\\work\\MessageBox.py','','',1)
42
Thank you for reading, I hope to help you, thank you for your support to this site!