0

夜遅くまで作成されないパスのスクリプトを一晩実行するバッチを作成しようとしています。パスが存在する場合、ループで合計 12 回チェックする必要があります。存在する場合は、スクリプト テストを開始します。存在しない場合は、1 時間スリープさせてから再度確認します。また、ループが毎回何回ループしたかを教えてもらいたいです。これが私が持っているものです...

@Echo off
cls
set build = %1
set counter = 1
for /l %%a in (1,1,12) do (
if exist {%build%} (
goto StartTest
        )
set Timer = %counter% + %Timer%
echo build does not exist. %Timer% out of 12 hours left for the build path to exist or this script will exit.
Sleep 3600000
)

goto end

:StartTest
Echo Starting Tests...

:end
Echo Times up, build path wasn't made

So far this has been the output in cmd:
build does not exist.  out of 12 hours left for the build path to exist or this
script will exit stop trying.
'Sleep' is not recognized as an internal or external command,
operable program or batch file.
build does not exist.  out of 12 hours left for the build path to exist or this
script will exit stop trying.
'Sleep' is not recognized as an internal or external command,
operable program or batch file.
build does not exist.  out of 12 hours left for the build path to exist or this
script will exit stop trying.
'Sleep' is not recognized as an internal or external command,
operable program or batch file.
build does not exist.  out of 12 hours left for the build path to exist or this
script will exit stop trying.
'Sleep' is not recognized as an internal or external command,
operable program or batch file.
build does not exist.  out of 12 hours left for the build path to exist or this
script will exit stop trying.
'Sleep' is not recognized as an internal or external command,
operable program or batch file.
build does not exist.  out of 12 hours left for the build path to exist or this
script will exit stop trying.
'Sleep' is not recognized as an internal or external command,
operable program or batch file.
build does not exist.  out of 12 hours left for the build path to exist or this
script will exit stop trying.
'Sleep' is not recognized as an internal or external command,
operable program or batch file.
build does not exist.  out of 12 hours left for the build path to exist or this
script will exit stop trying.
'Sleep' is not recognized as an internal or external command,
operable program or batch file.
build does not exist.  out of 12 hours left for the build path to exist or this
script will exit stop trying.
'Sleep' is not recognized as an internal or external command,
operable program or batch file.
build does not exist.  out of 12 hours left for the build path to exist or this
script will exit stop trying.
'Sleep' is not recognized as an internal or external command,
operable program or batch file.
build does not exist.  out of 12 hours left for the build path to exist or this
script will exit stop trying.
'Sleep' is not recognized as an internal or external command,
operable program or batch file.
build does not exist.  out of 12 hours left for the build path to exist or this
script will exit stop trying.
'Sleep' is not recognized as an internal or external command,
operable program or batch file.
Times up, build path wasn't made

C:\Users\james\Desktop>

sleep認識されていないコマンドであり、%Timer%空白であることに注意してください

4

3 に答える 3

2
set build = %1
set counter = 1

などの問題が発生する可能性があります。

スペースは重要です。set build = %1たとえば、この行では変数 " build" が " " ではなくスペースでbuild設定され、設定される値は " %1" ではなく " %1" になります (最初のパラメーターですが、先頭にスペースがあります)。

SLEEP は標準の実行可能ファイルではありません。試すTIMEOUT(実行する

timeout /?

ドキュメントのプロンプトから。

そして、TIMERどこにも設定されていません - [nothing] に置き換えられます


補遺: いくつかのデモンストレーション ルーチン

@ECHO OFF&SETLOCAL&cls
ECHO --- a little demonstration of SET syntax
@ECHO on
SET problem=this is fine
SET problem =this is a problem
@ECHO OFF
ECHO.
ECHO Result:
ECHO.
SET proble|FIND /i "problem"
ECHO.
ECHO See how the space is included in the variable NAME
ECHO so that there are two distinct variables?




@ECHO off&setlocal&CLS
ECHO Demonstrating the use of %%var%% IN a block
ECHO.
SET var=Original value
ECHO Before the block, %%var%%=%var%
FOR %%i IN (1 2 3) DO (
  SET var=New value %%i
  ECHO loop %%i : %%var%%=%var%
  )
ECHO After the block, %%var%%=%var%
ECHO.
ECHO BECAUSE the block is first PARSED, then executed.
ECHO in the parsing process, %%var%% is replaced by its
ECHO value as it stood when the block was parsed - BEFORE execution
ECHO.
ECHO now try using a SETLOCAL ENABLEDELAYEDEXPANSION command first:
ECHO.
SETLOCAL ENABLEDELAYEDEXPANSION
SET var=Original value
ECHO Before the block, %%var%%=%var% and ^!var^!=!var!
FOR %%i IN (1 2 3) DO (
  SET var=New value %%i
  ECHO loop %%i : %%var%%=%var% BUT ^^^!var^^^!=!var!
  )
ECHO After the block, %%var%%=%var% and ^^^!var^^^!=!var!
ECHO.


CALLENABLEDELAYEDEXPANSION と同じ最終結果を達成するために を使用することを示すための修正

@ECHO OFF
SETLOCAL
SET count=0
FOR /l %%i IN (1,1,10) DO (
  SET /a count+=1
  CALL ECHO Loop %%i: count=%%count%%
)

ここで起こることは、パーサーを使用して の CURRENT (つまり実行時) 値を取得することですCOUNT。これが実際に行うことは、エスケープする%%count%%ため%count%、秒を通常の文字と見なし、特別な意味を持たないので、に置き換えます。したがって、行 (eg)は で実行され、%count% は THEN-current 環境のパーサーによって適切に置き換えられます。%%%ECHO Loop 3: count=%count%CALL

SET/A発言にも注意。SET/Aは後で追加されSET、式の算術結果を変数に割り当てます。すべての環境変数は文字列であるため、文字列に変換されます。私が使用した構文は、ターゲットに 1 を追加する C スタイルの式です。最初の式が (eg)に解析され、ステートメントの評価全体でスペース (数字ではない) が無視されるようなものであるため、SET /A count=%count% + 1またはとして表現することもできます。set /a count = count + 1SET /a count=3 + 1SET/A

したがって、

set count=0
set /a count = 0

どちらも同じ目的を達成しますが、/aオピニオンが使用された場合のみです。

于 2013-04-04T05:27:59.323 に答える
0

再試行の場合 (なぜこれをもっと早く考えなかったのかわかりません)、echo %%a out of 12 triesループ内に行を追加するだけです。

于 2013-04-05T15:21:37.883 に答える