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?

5
  • 3
    What is the output of print destPath + '/BHC.exe'? Commented Nov 10, 2015 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')]). Commented Nov 10, 2015 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). Commented Nov 10, 2015 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! Commented Nov 10, 2015 at 16:42
  • Thanks for your information (and solution :-)! It works fine. Commented Nov 11, 2015 at 20:52

1 Answer 1

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?

Sign up to request clarification or add additional context in comments.

3 Comments

@tdelaney: But obviously doesn't, hence the question.
@martineau this answer Is extremely unlikely to fix the problem. Whatever causes OPs problem will still fail.mIt should be a comment.
@Erica Thank you! The os.path.join did the right thing :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.