简体   繁体   English

在Windows .bat文件中运行Python脚本

[英]Running Python script in my Windows .bat file

I have a .bat file, in the file I did: 我有一个.bat文件,在执行的文件中:

  1. cd to a direcotry cd到目录
  2. copied the files to another directory 将文件复制到另一个目录
  3. run the to-csv.vb program on the files 在文件上运行to-csv.vb程序
  4. deleted some files 删除了一些文件
  5. cd to another direction cd到另一个方向
  6. run my Python script. 运行我的Python脚本。

I'm stuck at step 6. Here is my code: 我陷入了第6步。这是我的代码:

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? 我可以执行第1-5步,但请坚持第6步。在.bat文件中运行Python脚本的正确语法是什么?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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