user1555863
user1555863

Reputation: 2607

Running external EXE from python

I'm running several portable apps from my python app.

Consider the following code:

import win32com.shell.shell as w32shell
import os
import sys
import win32process as process

PORTABLE_APP_LOCATION = "C:\\Windows\\System32\\calc.exe"

#This function runs a portable application:
def runPortable():
    try:
        startObj = process.STARTUPINFO()
        process.CreateProcess(PORTABLE_APP_LOCATION,None,None,None,8,8,None,None,startObj)
        # OR
        #w32shell.ShellExecuteEx(lpFile=PORTABLE_APP_LOCATION)
    except:
        print(sys.exc_info()[0])
runPortable()

1) Should I expect any differences in the execution of this code from pythonw or python ?

2) If I change PORTABLE_APP_LOCATION to the path to a portable version of CDBurnerXP and use the ShellExecuteEx option instead of CreateProcess, I see the process is started on Windows Task Manager but the actual window of the app isn't visible. This doesn't happen with other EXEs such as a portable version of GIMP that do show up after being ran. I assume this difference comes from a property of the executables. Anybody knows what's causing this?

3) Under what terms does Windows prompts the "Are you sure you want to run this EXE"? I believe CDBurnerXP is signed with a certificate but still sometimes Windows pops this question when trying to run this EXE from within python.

Thanks a lot.

Upvotes: 0

Views: 324

Answers (2)

Alexander
Alexander

Reputation: 12775

About Your first question , you should pay attention that when executing python code using pythonw.exe runtime , your sys.stdout buffer is limited to 4096 Bytes and when overflowed will throw an IOError wich you will not see because the code is running windowless .

Upvotes: 1

sinhayash
sinhayash

Reputation: 2803

I am a newbie in this field. May be this can help you

use subprocess.call, more info here:

import subprocess
subprocess.call(["C:\\temp\\calc.exe"])

or

import os
os.system('"C:/Windows/System32/notepad.exe"')

i hope it helps you...

Upvotes: 0

Related Questions