简体   繁体   中英

Windows Task Scheduler not allowing python subprocess.popen

I noticed a rather interesting problem the other day.

I have a windows scheduled task on Windows server 2008 RT. This task runs a batch file which runs a python script I've built. Within this python script there is a subprocess.Popen call to run several other batch files. However for the past couple days I've noticed that the task has successfully run however the secondary batch files did not. I know the python script ran successfully due to the logs it created and all the files it makes that the secondary batch files use are all there. However the completed files are not.

If I just run the batch file by itself everything works perfectly. Does Microsoft's task scheduler not allow a program to open additional batch files and is there a workaround for this?

I had exactly the same problem when task scheduler tries to call a .bat which runs a python script.

I found the trick is to put the path of the bat file in Start in (optional)

在此输入图像描述

Thanks to answer from Jordan8307 https://community.spiceworks.com/topic/531774-task-scheduler-fails-executing-bat-file-but-i-can-run-it-manually

Same situation: taks -> batch script -> Python process -> subprocess(es), but on Windows Server 2012

I worked around the problem by providing the absolute path to the script/exe in subprocess.Popen .

I verified the environment variables available inside the Python process and the script/exe is in a directory on the PATH . Still, Windows gives a FileNotFoundError unless I provide the absolute path.

Strangely, calling the same script/exe from the batch script is possible without providing its absolute path.

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