我有许多Python脚本,一个个点击运行它们非常麻烦。如何制作批处理文件一次性运行它们全部?
我有许多Python脚本,一个个点击运行它们非常麻烦。如何制作批处理文件一次性运行它们全部?
start /B python script1.py
start /B python script2.py
start /B python script3.py
在*nix上:
python script1.py &
python script2.py &
python script3.py &
start
命令来启动一个进程。@echo off
start "" foo.py
start "" bar.py
start "" baz.py
关于评论:“有没有办法启动这些最小化?”
您可以通过输入命令名称后跟 /?
来了解命令的工作方式。在本例中,start /?
告诉我们它的命令行选项包括:
MIN Start window minimized.
start "" /MIN quux.py
from apscheduler.schedulers.background import BackgroundScheduler
import datetime as dt
from os import system
from time import sleep
parallel_tasks = [["Drive:\YourPath\First.bat", 1], ["Drive:\YourPath\Second.bat", 3]]
def DatTijd():
Nu = dt.datetime.now()
return Nu
def GetStartTime(Nu, seconds):
StartTime = (Nu + dt.timedelta(seconds=seconds)).strftime("%Y-%m-%d %H:%M:%S")
return StartTime
len_li = len(parallel_tasks)
sleepTime = parallel_tasks[len_li - 1][1] + 3
Nu = DatTijd()
for x in range(0, len_li):
parallel_tasks[x][0] = 'start cmd /C ' + parallel_tasks[x][0]
# if you want the command window stay open after the tasks are finished use: cmd /k in the line above
delta = parallel_tasks[x][1]
parallel_tasks[x][1] = GetStartTime(Nu, delta)
JobShedul = BackgroundScheduler()
JobShedul.start()
for x in range(0, len_li):
JobShedul.add_job(system, 'date', run_date=parallel_tasks[x][1], misfire_grace_time=3, args=[parallel_tasks[x][0]])
sleep(sleepTime)
JobShedul.shutdown()
exit()
echo off
Title Python is running [Your Python Name]
cls
echo "[Your Python Name] is starting up ..."
cd Drive:\YourPathToPythonFile
python YourPyFile.py
python3
。 - kaliiiiiiiii