简体   繁体   中英

Running Python script in my Windows .bat file

I have a .bat file, in the file I did:

  1. cd to a direcotry
  2. copied the files to another directory
  3. run the to-csv.vb program on the files
  4. deleted some files
  5. cd to another direction
  6. run my Python script.

I'm stuck at step 6. Here is my code:

cd "Python\test1"
copy  "Python\test1\"*.xls*  "Python\test1\move"

FOR /f "delims=" %%i IN ('DIR *.xls* /b') DO to-csv.vbs "%%i" "%%i.csv" 
del "H2*.csv"
del "H6*.csv"
del "H3*.xlsx"

cd "H:\UCLAHealth\HIIN\Data Process\Python" #my python script1 is in this directory 

python script1.py  #this line didn't work.  

I'm ok with steps 1-5, but stuck on step 6. What's the correct syntax for running a Python script in .bat file?

You can either do this in your script:

set "python=C:\path to Python\python.exe"
"%python%" script1.py

Or you can execute it with full path:

"C:\Path to Python\python.exe" script1.py

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