0

I'm on day two of a desperate attempt to run a Windows executable from a Python script. This .exe file is opaque to me; in other words, I don't know how to open it up to look at the source code. But importantly, this executable needs to be located in the same directory as a csv file full of parameters in order to work.

When I call the file directly in the command line:

 C:\Users\pb\nw_river> Run_Model.exe

the executable works exactly as expected.

However, when I try to call the same file from some python code:

import subprocess

subprocess.Popen(["C:\Users\pb\nw_river\Run_Model.exe"], shell=True)

I receive error messages that indicate that the executable can't "see" the required csv file.

I don't have any of these problems when I run the script on my macbook (MacOS Catalina 10.15.3), but I really need to get this to run on my work computer, which has a Windows 10 Pro OS.

I'm a total noob to Windows. Has anyone ever experienced this issue, and do you have any advice? Thanks in advance!

  • sounds like you need to set the working directory to the directory where the exe file lives. – Garr Godfrey Mar 03 '20 at 23:51
  • see https://stackoverflow.com/questions/1685157/how-can-i-specify-working-directory-for-popen – Garr Godfrey Mar 03 '20 at 23:52
  • Please share the entire error message. You should use a raw string for the file path, by the way. Why are you using `shell=True` ? – AMC Mar 04 '20 at 02:30
  • @GarrGodfrey Thank you for that helpful link! I'll give that a shot. – polyp_bureau Mar 04 '20 at 04:56
  • @AMC Sorry, I know I wasn't clear about the error message. There actually is no error message from the above code; the executable runs fine. I decided against posting the "errors" thrown by the executable because they're really just some print statements inside the file that indicate that the csv was not properly loaded; I didn't think they would help here.. – polyp_bureau Mar 04 '20 at 04:57

0 Answers0