2

I am trying to run a .exe file in python2.7. I have tried everything I could from searching it. Here are some code I have tried:

subprocess.Popen(r"C:\Programs Files\Internet Explorer\iexplore.exe")

And:

subprocess.Popen(["cmd","/c",r"C:\Programs Files\Internet Explorer\iexplore.exe"])

And:

os.popen(r"C:\Programs Files\Internet Explorer\iexplore.exe")

All except the first one(which brings up a Windows Error) do not seem to run iexplore.exe.

Is there another way to run an .exe file?

  • 6
    It's "Program Files" (and possibly "Program Files (x86)" on 64-bit Windows versions). Also try and use forward slashes. You may also need to have quotes in your string if your path has spaces in it (maybe). – Thomas Nov 08 '13 at 01:16
  • 1
    The slashes aren't the problem; he's using raw strings. It's just the misspelled path. – abarnert Nov 08 '13 at 01:30
  • 2
    @Thomas you only need to escape or quote spaces in paths when you pass `shell=True` to `Popen`. Using forward slashes *can* make your life easier in some situations, but it's irrelevant here - Windows accepts both equally as path separators, in all situations. – lvc Nov 08 '13 at 01:37
  • @lvc Thanks for the clarifications - I prefer to use forward slashes everywhere personally, even if just to not deal with escaped characters. Didn't know about the `shell` flag, cheers. – Thomas Nov 08 '13 at 01:39
  • I was just looking at an identical SO thread. This one may in fact be more informative, but there are lots of questions on this topic already, you may want to look into that. – trevorKirkby Dec 01 '13 at 05:24

3 Answers3

8

If you just want to open the webbrowser, you could do this instead:

import webbrowser
webbrowser.open('www.google.com')
Wayne Werner
  • 49,299
  • 29
  • 200
  • 290
5

As Thomas explained in a comment, C:\Programs Files is not a standard directory on Windows. You could, of course, create a directory with that name, but it's unlikely that you've done so. Most likely you wanted C:\Program Files (notice Program vs. Programs).

The best way to avoid problems like this is to open the folder in Explorer, turn on the address bar, and copy and paste the path directly into your code. Then you'll know it's correct.

Also, you really should look at what the WindowsError says. It will almost certainly have some text about not being able to find such a file. Even if that doesn't help you, it would help people trying to solve your problem for you on a site like SO.

abarnert
  • 354,177
  • 51
  • 601
  • 671
0

If you just want to execute iexplore.

Import os

os.system('start iexplore.exe')
AcK
  • 2,063
  • 2
  • 20
  • 27
James
  • 1