Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #72660
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2014-06-04 13:25 -0700 |
| References | (4 earlier) <mailman.10417.1401306385.18130.python-list@python.org> <cc381969-d75b-42ce-81fe-5577501b1e06@googlegroups.com> <mailman.10449.1401363665.18130.python-list@python.org> <fe0d5d14-e7eb-4b60-90a4-12ff1dd74e17@googlegroups.com> <mailman.10524.1401640265.18130.python-list@python.org> |
| Message-ID | <960879f7-4bb8-44bf-907f-fcc3397ef7d9@googlegroups.com> (permalink) |
| Subject | Re: Command prompt not shown when running Python script with subprocess on Windows |
| From | ps16thypresenceisfullnessofjoy@gmail.com |
Thanks again for your help. I tried something similar to what you suggested:
def run_app(self, app_path):
args = shlex.split(app_path.replace("\\", "\\\\"))
args = [arg.replace("\\\\", "\\") for arg in args]
args[0] = os.path.expandvars(args[0])
try:
if pywin32:
exe = win32api.FindExecutable(args[0])[1]
if exe != os.path.abspath(args[0]):
args.insert(0, exe)
subprocess.Popen(args)
except Exception:
return False
return True
where pywin32 is a global variable defined earlier in my program based on whether or not the win32api module is available.
This code generally works quite well, but with one problem. I have in my XML file a line like this:
<app name="Notepad++" checked="false">%ProgramFiles%\Notepad++\notepad++.exe C:\Users\Timothy\Documents\Python\StartupPlus\apps.xml</app>
Within the try statement, the variable 'args' contains this list, as expected:
['C:\Program Files (x86)\Notepad++\notepad++.exe', 'C:\Users\Timothy\Documents\Python\StartupPlus\apps.xml']
But the 'exe' variable returned by win32api.FindExecutable is not what I would expect:
C:\PROGRA~2\NOTEPA~1\NOTEPA~1.EXE
Because of this, the boolean comparison:
if exe != os.path.abspath(args[0]):
returns True when it should return False, since it is comparing a short (MS-DOS) path name with a long path name.
Should I use win32file.GetLongPathName to fix this problem, or do you know of a better solution?
-- Timothy
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Command prompt not shown when running Python script with subprocess on Windows ps16thypresenceisfullnessofjoy@gmail.com - 2014-05-26 17:03 -0700
Re:Command prompt not shown when running Python script with subprocess on Windows Dave Angel <davea@davea.name> - 2014-05-27 03:20 -0400
Re: Command prompt not shown when running Python script with subprocess on Windows Stephen Hansen <me+python@ixokai.io> - 2014-05-26 23:38 -0700
Re: Command prompt not shown when running Python script with subprocess on Windows ps16thypresenceisfullnessofjoy@gmail.com - 2014-05-27 16:01 -0700
Re: Command prompt not shown when running Python script with subprocess on Windows Tim Golden <mail@timgolden.me.uk> - 2014-05-28 06:08 +0100
Re: Command prompt not shown when running Python script with subprocess on Windows ps16thypresenceisfullnessofjoy@gmail.com - 2014-05-28 13:22 -0700
Re: Command prompt not shown when running Python script with subprocess on Windows Tim Golden <mail@timgolden.me.uk> - 2014-05-28 20:46 +0100
Re: Command prompt not shown when running Python script with subprocess on Windows ps16thypresenceisfullnessofjoy@gmail.com - 2014-05-28 13:46 -0700
Re: Command prompt not shown when running Python script with subprocess on Windows Tim Golden <mail@timgolden.me.uk> - 2014-05-29 12:41 +0100
Re: Command prompt not shown when running Python script with subprocess on Windows ps16thypresenceisfullnessofjoy@gmail.com - 2014-05-29 12:21 -0700
Re: Command prompt not shown when running Python script with subprocess on Windows Tim Golden <mail@timgolden.me.uk> - 2014-06-01 17:31 +0100
Re: Command prompt not shown when running Python script with subprocess on Windows ps16thypresenceisfullnessofjoy@gmail.com - 2014-06-04 13:25 -0700
csiph-web