[英]Execute an .exe in Python in Ubuntu/WSL
如何在 WSL 中的 Ubuntu 上使用 Python3 執行.exe
文件? 從我的搜索中,我找到os.system
,但盡管放置在正確的文件夾中,但我找不到.exe
文件。 我也試過os.open
沒有結果。
import os
current = os.chdir('../../../Programmi/OWASP/Zed Attack Proxy/')
os.system("ZAP.exe")
嘗試使用完全限定的路徑:
os.system("../../../Programmi/OWASP/Zed Attack Proxy/ZAP.exe")
為了稍微解釋@MichaelMatsaev的回答,您嘗試對問題中的 Python 示例進行的操作與此 Bash 構造基本相同:
cd ../../../Programmi/OWASP/Zed Attack Proxy/
ZAP.exe
你會得到一個從 Bash command not found
。 幾乎每個 Linux 應用程序都將以相同的方式工作,因為它們最終都在exec
系列中使用某種形式的系統調用。
在 Linux(不僅僅是 WSL 中的 Windows .exe
)中執行任何二進制文件時,該二進制文件必須是:
$PATH
因此,除了@MichaelMatsaev 的(正確)建議使用:
os.system("../../../Programmi/OWASP/Zed Attack Proxy/ZAP.exe")
以下方法也可以:
os.chdir('../../../Programmi/OWASP/Zed Attack Proxy/')
os.system("./ZAP.exe")
而且,雖然在這種情況下這有點病態(即我無法想象你會想要這樣做),但你甚至可以修改代碼中的搜索路徑,然后在沒有完全限定路徑的情況下調用二進制文件:
os.environ['PATH'] += os.pathsep + '../../../Programmi/OWASP/Zed Attack Proxy/'
os.system("ZAP.exe")
旁注:AFAIK,沒有理由嘗試將os.chdir
存儲到current
變量中,因為os.chdir
不返回值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.