Launching *.exe files with Python (Windows 7)


SUBMITTED BY: YouKnowNothing

DATE: Dec. 23, 2015, 11:28 a.m.

UPDATED: Dec. 23, 2015, 11:29 a.m.

FORMAT: Text only

SIZE: 836 Bytes

HITS: 4885

  1. Sometimes doing the most simple tasks with Python can be challenging. Launching *.exe files with Python is a problem I encountered recently.
  2. Imagine a file, such as "c:/hello/hello.exe". The simplest way to launch this is:
  3. import os
  4. os.system("start c:/hello/hello.exe");
  5. This is a great and simple method. But what if the directory has a space in it? Spoiler: It won't work. But there is a workaround. Open up command prompt and try the following
  6. mklink /j <link> <folder>
  7. Let's say you want to execute "c:/hello hello/hello.exe" from python. You could do this:
  8. mklink /j c:\hello2 "c:\hello hello"
  9. This means that now c:/hello2 be EQUIVALENT to "c:/hello hello", meaning that the file "c:/hello hello/hello.exe" can be executed by:
  10. import os
  11. os.system("start C:/hello2/hello.exe")

comments powered by Disqus