@echo off
SetLocal EnableExtensions EnableDelayedExpansion

set "scriptfile=%~f0"
set "scriptbase=%~n0"
set "scriptname=%~nx0"
set "scripthome=%~dp0"
set "script_py=%scripthome%\%scriptbase%.py"

:ParseArgs
set "cmds= "
set "args= "
:ParseLoop
if "%~1" == "" goto :ParseDone
set "arg=%~1"
if "!arg:~0,1!" == "@" goto :ParseCmds
set "args=!args! !arg!"
shift /1 & goto :ParseLoop
goto :ParseDone
:ParseCmds
set "cmds=!cmds! !arg!"
shift /1 & goto :ParseLoop
goto :ParseDone
:ParseDone
:TrimArgs
if "!args:~0,1!" == " " set "args=!args:~1!"
if "!args:~0,1!" == " " goto :TrimArgs
:TrimCmds
if "!cmds:~0,1!" == " " set "cmds=!cmds:~1!"
if "!cmds:~0,1!" == " " goto :TrimCmds
:CallPythonScript
if "!cmds:~0,1!" == "@" goto :CallPipe
goto :CallAsIs
goto :EOF

:CallPipe
unix printf "%cmds%" | "%script_py%" !args!
exit /b %errorlevel%
goto :EOF

:CallAsIs
call "%script_py%" !args!
exit /b %errorlevel%
goto :EOF

::::::::::::::
:: END OF FILE
::::::::::::::
