::Обязательные параметры:
::-bindir - путь до "родной" утилиты
::Не обязательные параметры:
::-pwd    - пароль пользователя бд, прокидывается в $PGPASSWORD
::Все остальные параметры "прокидываются" без изменений в "родную" утилиту
::Рогожин И.Н. 30.11.2016
@echo off
set PGDATABASE=
set PGHOST=
set PGOPTIONS=
set PGPORT=
set PGUSER=
::Loop through args
setlocal enabledelayedexpansion
set argCount=0
for %%x in (%*) do (
   set /A argCount+=1
   set "argVec[!argCount!]=%%~x"
)
::echo.
::echo Number of processed arguments: %argCount%
::echo.
set pwd=
set bindir=
set newargs=
set argcnt=2
if %argCount% geq 2 (
	for /L %%i in (1,1,%argCount%) do (
		::echo !argVec[%%i]!
		if %%i==1 (
			if [!argVec[1]!]==[-pwd] set pwd=!argVec[2]!
			if [!argVec[1]!]==[-bindir]	set bindir=!argVec[2]!
		)
		if %%i==3 (
			if [!argVec[3]!]==[-pwd] (
				set pwd=!argVec[4]!
				set argcnt=4
			)
			if [!argVec[3]!]==[-bindir]	(
				set bindir=!argVec[4]!
				set argcnt=4
			)
		)
		if %%i gtr %argcnt% (
			set newargs=!newargs! "!argVec[%%i]!"
		)
	)
)

set utilname=%~n0.exe
::echo Util name is "%utilname%"
::echo.
::echo Catched password is "%pwd%"
::echo.
::echo Catched bindir is "%bindir%"
::echo.
::echo Passed through params is "%newargs%"
::echo.

::if "%pwd%" == "" (
::	echo Expected -pwd argument
::	goto end
::)

if "%bindir%" == "" (
	echo Expected -bindir argument
	goto end
)

::SETLOCAL ENABLEEXTENSIONS
::IF ERRORLEVEL 1 ECHO Unable to enable extensions
::IF DEFINED PGPASSWORD (ECHO PGPASSWORD before "%PGPASSWORD%") ELSE (ECHO PGPASSWORD is NOT defined before)
::ENDLOCAL

set PGPASSWORD=%pwd%

::echo PGPASSWORD after "%PGPASSWORD%"

::echo "%bindir%\%utilname%" %newargs%
::echo.

call "%bindir%\%utilname%" %newargs%

:end
::exit 0

