Command prompt not shown when running Python script with subprocess on Windows

ps16thypresenceisfullnessofjoy at gmail.com ps16thypresenceisfullnessofjoy at gmail.com
Tue May 27 19:01:34 EDT 2014


Sorry for not being explicit enough. I am aware that this would work if I called python.exe path-to-script.py with shell=False.

In my Python program, I parse an XML file like the one I have included below. Then I loop through the paths of the apps listed in it and run them by calling something like this:

for app_path in app_paths:
    args = shlex.split(app_path.replace("\\", "\\\\"))
    args = [arg.replace("\\\\", "\\") for arg in args]
    args[0] = os.path.expandvars(args[0])
    subprocess.Popen(args, shell='__WXMSW__' in wx.PlatformInfo)

I want users to be able to enter paths in the XML file exactly the way they would be entered in a Windows shortcut. Since it is possible to make a Windows shortcut for path-to-script.py without the python.exe in front of it and have it open in its own command prompt, I want to be able to do the same thing in my XML file, but this is what I cannot figure out.

By the way, is there a simpler way to use shlex.split and return valid Windows paths than the way I am doing (as shown above)?

Thank you.

-- Timothy

*** Contents of app_list.xml below ***

<?xml version='1.0' encoding='utf-8'?>
<apps>
  <app name="Mozilla Firefox">%ProgramFiles%\Mozilla Firefox\firefox.exe</app>
  <app name="Mozilla Thunderbird">%ProgramFiles%\Mozilla Thunderbird\thunderbird.exe</app>
  <app name="LibreOffice Writer">%ProgramFiles%\LibreOffice 4\program\swriter.exe "C:\Users\Timothy\Documents\myfile.odt"</app>
  <app name="**Python script**">C:\Users\Timothy\Documents\Python\myscript.py</app>
</apps>



More information about the Python-list mailing list