python运行其他程序

一 使用os.system()函数运行其他程序

打开系统的记事本程序
  1. >>>import os
  2. >>> os.system('notepad')
  3. 0
  4. >>> os.system('notepad python.txt')
  5. 0
 
二 使用ShellExecute函数运行其他程序
  1. >>>import win32api
  2. >>> win32api.ShellExecute(0,'open','notepad.exe','','',0)
  3. 42
  4. >>> win32api.ShellExecute(0,'open','notepad.exe','','',1)
  5. 42
  6. >>> win32api.ShellExecute(0,'open','notepad.exe','python.txt','',1)
  7. 42
  8. >>> win32api.ShellExecute(0,'open','http://www.python.org','python.txt','',1)
  9. 42
  10. >>> win32api.ShellExecute(0,'open','E:\\python\\work\\Demo.mp3','','',1)
  11. 42
  12. >>> win32api.ShellExecute(0,'open','E:\\python\\work\\MessageBox.py','','',1)
  13. 42

猜你喜欢

转载自cakin24.iteye.com/blog/2383708