@echo off
setlocal
:: Check 1st argument for help.
if "%~1" == "-h" goto :help
if "%~1" == "--help" goto :help
if "%~1" == "/?" goto :help
:: Check script arguments for program.
set _program=%*
:: If not program defined, prompt for program.
if not defined _program set /p "_program=Enter the program: "
:: If the required program is not defined then exit.
if not defined _program exit /b 1
:: Set a prompt string.
set "_prompt=%_program:"='%>"
:: Show information before start of the loop.
echo Pass arguments to '%_program%' in a loop.
echo.
:begin_loop
:: Prompt for arguments.
set "_args="
set /p "_args=%_prompt% "
:: Restart loop if no args or exit if requested.
if not defined _args goto :begin_loop
if /i "%_args:"='%" == "exit" exit /b 0
:: Clear local variables and then run the program with arguments.
setlocal
set "_prompt=" & set "_program=" & set "_args=" & %_program% %_args%
endlocal
echo.
goto :begin_loop
:help
:: Help information.
echo Pass arguments to a select program in a loop.
echo If script arguments are passed, then that will be the program.
echo If a program is not defined, then a prompt will ask for a program.
echo Variables _prompt, _program and _args are cleared with each execution.
This is same as I have posted at my website, except a line
removed that sets a ANSI escaped prompt for conemu. Doubt this
site would keep the control character intact if posted.
I call it loop.cmd and place it in PATH (see note). It is made for any
command so is universal.
To use:
loop command
then you will get a prompt with the command in it i.e.
command>
What you type at the prompt now will be prefixed with
command and executed.
You can just type exit
to end the loop.
Based on your code example of use:
loop php bin/console
then add your command at the prompt:
php bin/console> command
A Python version exists too though I use the batch file
as it keeps auto completion etc.
Note:
The PATH I mention is where the script can find files on your system.
A path in the PATH
environmental variable or the current
working directory.
Recommend creating a folder path i.e. %SystemDrive%\bin
and add
that to the system variable PATH
where your PATH
suitable
scripts can be stored. Or you could just add the script to an
existing directory in the variable PATH
if you are uncomfortable
to add your own directory to PATH
.
How to set the path and environment variables in Windows