简体   繁体   中英

Batch file to execute python script

I'm trying to write a batch file to execute a python script and not having much luck. I tried the following:

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

but get the following error:

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.

It may be easiest to specify the full path to the Python executable. That way you don't have to worry about the PATH environment variable.

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

If you absolutely need to set the PATH environment variable, you would do it like this:

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

Note that the path to the Python folder goes before the previous contents of PATH; this ensures that that is the Python that gets run if you have multiple Python installations on you computer.

  1. You need to have your FULL path in quotes. Example: SET path to "C:\\Program Files\\python37\\python.exe"
  2. You don't need to SET the path, you can do what Jack mentioned in a past comment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM