@echo off setlocal EnableExtensions EnableDelayedExpansion set __argc=0 for %%i in (%*) do ( set /a __argc+=1 set "__argv[!__argc!]=%%~i" ) set "result_path=!__argv[1]!" set "test_action=!__argv[2]!" set "temp_result_path=%result_path%.tmp" >"%temp_result_path%" >"%temp_result_path%" echo.!__argv[%%i]! ) goto finish :dump_env for /l %%i in (3,1,%__argc%) do ( >>"%temp_result_path%" call :dump_env_var "!__argv[%%i]!" ) goto finish :dump_env_var if defined %~1 ( echo.!%~1! ) else ( echo.^ ) exit /b 0 :dump_cwd >>"%temp_result_path%" echo.%CD% goto finish :finish >nul move /y "%temp_result_path%" "%result_path%" exit /b 0