Skip to content

Instantly share code, notes, and snippets.

@maphew
Last active August 29, 2015 14:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maphew/7bd9f0af1914cc7839ba to your computer and use it in GitHub Desktop.
Save maphew/7bd9f0af1914cc7839ba to your computer and use it in GitHub Desktop.
Print the command line to screen and then execute it. Useful when you want to have echo turned off everywhere else, and not speckle code with `echo on && {cmd line here} && @echo off`
@echo off
:: --- Run.bat ---
:: Echo the command line to screen and then execute it.
::
:: Useful when you want to have echo turned off everywhere else,
:: and not speckle code with `echo on && {cmd line here} && @echo off`
if "%*"=="" goto :Usage
setlocal
echo === Run =================
set _cmd=%*
echo %_cmd%
call %_cmd%
if not %errorlevel%==0 (echo. && echo *** Non-zero exit code: %errorlevel%)
echo =========================
endlocal
goto :eof
:Usage
echo.
echo. Usage: %~n0 [command] {parameters}
echo.
goto :eof
@echo off
call :run [command -par1 -par2 in_thing out_thing]
goto :eof
:: ---------------------------------------------------------------------------
:run
:: Echo the command line to screen and then execute it.
::
:: Useful when you want to have echo turned off everywhere else,
:: and not speckle code with `echo on && {cmd line here} && @echo off`
setlocal
set _cmd=%*
echo %_cmd%
%_cmd%
if not %errorlevel%==0 (echo. && echo *** Exit code: %errorlevel% && echo.)
endlocal
goto :eof
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment