Created
June 26, 2014 00:18
-
-
Save sdesalas/79fd45cc6a9ad000d6c2 to your computer and use it in GitHub Desktop.
Batch file for parsing input characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@if (1==1) @if(1==0) @ELSE | |
@echo off | |
@SETLOCAL ENABLEEXTENSIONS | |
:: CHECK IF WE NEED TO MODIFY PATH | |
ECHO ;%PATH%; | find /C /I ";%~dp0tools\phantomjs;" > NUL | |
IF %ERRORLEVEL% GTR 0 ( | |
ECHO Adding phantom and casper to PATH | |
SET "path=%path%;%~dp0tools\phantomjs;%~dp0tools\casperjs\batchbin" | |
) | |
:: EXECUTE AFTER REPARSING BATCH INPUT | |
IF "%SPECIALPARSE%"=="*%~f0" ( | |
:: SECOND RUN - EXECUTE | |
ECHO casperjs.bat test "%targetdir%\run.js" --joyful-target=%target% --xunit=test-reports\latest.xml %~2 %~3 %~4 %~5 %~6 %~7 %~8 %~9 | |
casperjs.bat test "%targetdir%\run.js" --joyful-target=%target% --xunit=test-reports\latest.xml %~2 %~3 %~4 %~5 %~6 %~7 %~8 %~9 | |
) ELSE ( | |
:: FIRST RUN - SETUP | |
SET target=%1 | |
SET targetdir=%~dp0 | |
SET "SPECIALPARSE=*%~f0" | |
cscript //E:JScript //nologo "%~f0" %* | |
) | |
@goto :EOF | |
@end @ELSE | |
w=WScript,wa=w.Arguments,al=wa.length,Sh=w.CreateObject("WScript.Shell"),p=""; | |
for(i=0;i<al;++i)p+="\"--"+wa.Item(i)+"\" "; | |
function PipeStream(i,o){for(;!i.AtEndOfStream;)o.Write(i.Read(1))} | |
function Exec(cmd,e){ | |
try{ | |
e=Sh.Exec(cmd); | |
while(e.Status==0){ | |
w.Sleep(99); | |
PipeStream(e.StdOut,w.StdOut); | |
PipeStream(e.StdErr,w.StdErr); | |
} | |
return e.ExitCode; | |
}catch(e){return e.number;} | |
} | |
w.Quit(Exec("\""+WScript.ScriptFullName+"\" "+p)); | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage as follows
This in turn get transformed into:
The reason for all the messy
WScript
code is to ensure we dont lose the equals=
sign for each input parameter in the process. Otherwise the input is only available as: