python - 无法对包含 .py 文件的批处理文件进行任务调度以在 Windows 10 中启动
问题描述
我有以下批处理文件
SET logfile="C:\Reports\logbatch.log"
@echo off
@echo Starting Script at %date% %time% >> %logfile%
"C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\python.exe"
"C:\Users\mypc\source\repos\WebS\WebS\Start_Master.py"
@echo finished at %date% %time% >> %logfile%
pause
Start_Master.py包含与 Start_Master.py 位于同一文件夹中的其他几个脚本
如果我手动运行批处理文件,它可以工作。
当我创建任务并且任务自动或手动运行时,我得到它无法打开文件
python: can't open the file 'script1.py' No such file or directory
python: can't open the file 'script2.py' No such file or directory
python: can't open the file 'script3.py' No such file or directory
解决方案
尝试:
SET logfile="C:\Reports\logbatch.log"
@echo off
@echo Starting Script at %date% %time% >> %logfile%
cd "C:\Users\mypc\source\repos\WebS\WebS\"
"C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\python.exe"
"C:\Users\mypc\source\repos\WebS\WebS\Start_Master.py"
@echo finished at %date% %time% >> %logfile%
pause
尝试将CWD(当前工作目录)更改为Start_Master.py所在的目录
推荐阅读
- mongodb - Mongo查询,分组数组条目
- php - Paypal PHP API SDK - 为购买人设置电子邮件地址
- java - java - 如何使用另一个堆栈反转java中的堆栈?
- python - 安装在 root 上的软件包是否在 virtualenv 中可用?
- python - 在 Google App Engine 中部署 python 时出错
- ms-access - 查询不使用 MS-Access 中的日期条件进行拉取
- r - 如果横向太长,Bookdown数字标题会失败?
- c# - 对象列表的所有组合。所有的对象都归结为一个单独的对象
- jenkins - 在 Jenkins for Android 项目中集成声纳时出现问题
- garbage-collection - HeapDumpBeforeFullGC应该在生产环境中使用吗?