windows cmd 腳本例子

簡單 windows cmd 腳本例子

判斷文件或文件夾是否存在

if not exist .git (
REM 判斷 true 執行 git 命令
  git init
) else (
REM 判斷 false
  echo skip git init
)

循環判斷某進程是否存在,並執行相應事件

@echo off
REM 設置標題
title rest
REM 定義變量
:again
REM 任務列表 查詢 指定可執行文件
tasklist|find /i "cci-agent.exe"
REM 判斷結果
if ERRORLEVEL 1 (
REM 不存在
    echo "start cci-agent.exe"
REM 執行文件
    start D:\coding-runner\cci-agent.exe up -d --config D:\coding-runner\.coding
)
REM choice 延遲 /t 3600 秒
choice /t 3600 /d y /n >nul
REM 執行變量
goto again
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章