Python to invoke Windows EXE executable program __python

Source: Internet
Author: User

#传参调用exe程序 (Resolve relative path, feel path problem), wait for EXE process to end, this program only ends.

#-*-coding:utf-8-*-

Import OS, Os.path, sys
Import Win32process, Win32event

Exe_path = sys.argv[1]
Exe_file = sys.argv[2]

#os. ChDir (Exe_path)

Try:
Handle = win32process. CreateProcess (Os.path.join (Exe_path, Exe_file),
', none, none, 0,
Win32process. Create_no_window,
None,
Exe_path,
Win32process. Startupinfo ())
running = True
Except Exception, E:
Print "Create error!"
Handle = None
running = False

While running:
rc = Win32event. WaitForSingleObject (Handle[0], 1000)
if rc = = win32event. WAIT_OBJECT_0:
running = False
#end While
Print "GoodBye"

#需要用的模块: Pywin32-214.win32-py2.5.exe

Change the program into an EXE program, you can call anywhere (under Windows system).

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.