How can I execute an .exe
file with Python3 on Ubuntu in WSL? From my searches I found os.system
, but despite being placed in the correct folder, I cannot find the .exe
file. I also tried with os.open
with no results.
import os
current = os.chdir('../../../Programmi/OWASP/Zed Attack Proxy/')
os.system("ZAP.exe")
2
Answers
Try using a fully-qualified path:
To expound on @MichaelMatsaev’s answer a bit, what you are attempting to do with the Python example in your question is essentially the same as this Bash construct:
You’ll get a
command not found
from Bash. Pretty much every Linux app will work the same way, since they all ultimately use some form of syscall in theexec
family.When executing any binary in Linux (not just Windows
.exe
‘s in WSL), the binary must be either:$PATH
So in addition to @MichaelMatsaev’s (correct) suggestion to use:
The following would work as well:
And, while it would be a bit pathologic (i.e. I can’t imagine you’d want to do it) for this case, you could even modify the search path inside the code and then call the binary without a fully-qualified path:
Side-note: AFAIK, there’s no reason to attempt to store the
os.chdir
into thecurrent
variable, asos.chdir
doesn’t return a value.