簡體   English   中英

制作一個批處理文件以運行 python 腳本一段時間,然后自動關閉

[英]Make a batch file to run python script for a certain amount of time and then auto-closes after

我需要制作一個批處理文件來刪除每次腳本啟動時創建的文件,然后設置一個計時器來停止 python 腳本並在一定時間后退出它以運行另一個命令行。 這是代碼,我找不到任何解決方案。 問題是 python 程序有點復雜,我無法修改它,所以我所能做的就是創建一個無限期執行此任務的批處理或 powershell 文件。 這是批處理文件:

cd C:\Users\Admin\Desktop\instabot.py-master
del -f user.session
instabot-py @user
#Here I need a line to stop the instabot-py running on cmd maybe using a condition before launching the script

我感到迷茫,我想不出辦法,並且必須是一個循環,例如每 5 分鍾一次又一次地執行所有這些代碼(運行 python 程序 5 分鍾然后關閉它並重新開始使用 cd, del, 啟動程序並再次停止。 PS:我在 windows 10 x64 上。

您可以為此使用 powershell 作業:

$myScript = {
    cd c:\some\folder
    python .\py_script.py
}

$timeOut = 10

while ($true){
    $job = start-job -ScriptBlock $myScript
    Start-Sleep $timeOut
    Remove-Item -Path .\some.file
    stop-job -Job $job 
    Remove-Job -Job $job
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM