@echo off setlocal enableextensions enabledelayedexpansion set has_host=0 set user_next=0 set user_name= set host_name= set command= for %%a in (%*) do ( if "%%a"=="-l" ( if "!has_host!"=="1" ( set command=!command! %%a ) else ( set user_next=1 ) ) else ( if "!user_next!"=="1" ( set user_next=0 set user_name=%%a ) else ( if "!has_host!"=="0" ( set host_name=%%a set has_host=1 ) else ( set command=!command! %%a ) ) ) ) set is_local=0 if "%user_name%"=="%USERNAME%" ( if "%host_name%"=="localhost" ( set is_local=1 ) ) if "%is_local%"=="1" ( %COMSPEC% /c %command% ) else ( %CVS_RSH% -l %user_name% %host_name% %command% ) endlocal