簡體   English   中英

執行python腳本的批處理文件

[英]Batch file to execute python script

我正在嘗試編寫一個批處理文件來執行 python 腳本,但運氣不佳。 我嘗試了以下方法:

@echo off
SET path C:\"Program Files\python37\python.exe"
C:\"projects\systemcheck.py -c systems.csv"

但得到以下錯誤:

C:\projects>nexus-script.bat Environment variable path C:\"Program
Files\python37\python.exe" not defined 'C:\"projects\systemcheck.py -c
systems.csv"' is not recognized as an internal or external command,
operable program or batch file.

指定 Python 可執行文件的完整路徑可能是最簡單的。 這樣您就不必擔心 PATH 環境變量。

@echo off                                                                                                                                                                   
"C:\Program Files\python37\python.exe" C:\projects\systemcheck.py -c systems.csv

如果您絕對需要設置 PATH 環境變量,您可以這樣做:

@echo off                                                                                                                                                                   
SET "PATH=C:\Program Files\python37;%PATH%"
python C:\projects\systemcheck.py -c systems.csv

請注意,Python 文件夾的路徑位於 PATH 之前的內容之前; 如果您的計算機上有多個 Python 安裝,這可以確保這是運行的 Python。

  1. 您需要在引號中包含完整路徑。 示例:將路徑設置為“C:\\Program Files\\python37\\python.exe”
  2. 你不需要設置路徑,你可以做傑克在過去的評論中提到的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM