0

I'm not able to start an executable from a variable path. I've tried:

os.system(destPath + '/BHC.exe')
os.system(destPath/BHC.exe)

the destPath is set correctly and the BHC.exe is in there.

How can I start the external program?

Vroluk
  • 41
  • 1
  • 4
  • 3
    What is the output of `print destPath + '/BHC.exe'`? – Undo Nov 10 '15 at 15:27
  • 1) Do not use `os.system` but `subprocess.call` instead 2) Use `os.path.join` instead of manually joinining the file paths: `import os, subprocess; subprocess.call([os.path.join(destPath, 'BHC.exe')])`. – Bakuriu Nov 10 '15 at 15:29
  • On Windows, `os.system` uses Windows components like `cmd.exe` which don't understand paths with forward slashes in them. Assuming `destpath` doesn't have any, try `+ '\\BHC.exe'` (or better yet do as @Erica suggests). – martineau Nov 10 '15 at 15:54
  • @martineau `os.system` understands forward slashes for absolute paths but not relative paths. We'll know what's going on when OP finally answers @Undo's question. Why people post questions and then ignore requests for more information is the puzzling part! – tdelaney Nov 10 '15 at 16:42
  • Thanks for your information (and solution :-)! It works fine. – Vroluk Nov 11 '15 at 20:52

1 Answers1

1

Use os.path.join to avoid any slash confusion:

os.system(os.path.join(destPath, 'BHC.exe'))

If that doesn't resolve the problem, further troubleshooting is best answered by running an outside program (executable) in python?

Community
  • 1
  • 1
Erica
  • 2,399
  • 5
  • 26
  • 34