0

ユーザーがキーを押すまで一時停止して待機するバッチ ファイルのセクションがあります。

しかし、自分の自由意志で実行中にバッチ ファイルを一時停止する機能が必要な場合はどうすればよいでしょうか。

バッチ ファイルは、ユーザー入力変数を作成します。

SET /P userInput= enter something here

プロセスの後半で、そのユーザー変数を更新したい場合があります。しかし、それは予期せぬ時に発生します。

バッチ ファイル プロセスを中断してから、バッチ プロセス全体を停止または終了せずに変数を更新できますか?

基本的には、バッチ ファイルが一意のファイル名を作成しており、その命名構造を更新する必要がある場合があります。プログラムを停止して、その変数を変更するだけでよいのです。

プログラムが開始されます:

Set /p userInput : something entered

does stuff..
does stuff..

//User hits  a key and program pauses
//prompt for userInput variable again:

Set /p userInput : something new

// then continue as normal

does stuff..
does stuff..

等..

バッチが別のオプションとして実行されている間に、キーボードを押してサブルーチンを呼び出すことは可能でしょうか?

読んでくれてありがとう!!

4

1 に答える 1

1

The Batch file below do exactly what you requested:

@echo off
setlocal
if "%1" neq "" goto %1

SET /P userInput= enter something here

echo Start batch
del flagFile.txt 2> NUL
"%~F0" Input | "%~F0" Process
echo End batch
goto :EOF


:Input
rem Wait for any key
pause > NUL
rem Get the new value
cd . > flagFile.txt
set /P "userInput=Enter new value: " > CON
echo %userInput%
goto Input


:Process
echo Current value: %userInput%
ping localhost -n 2 > NUL
if not exist flagFile.txt goto Process
set /P "userInput="
del flagFile.txt
goto Process

Note that you had not stated how the process ends, so I will add such part as soon as you describe this point...

于 2015-11-23T23:51:56.243 に答える