Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[Batch] JScript and Batch Hybrid
@if (@CodeSection == @Batch) @then
:: The first line above is...
:: in Batch, a valid IF command that does nothing.
:: in JScript, a conditional compilation IF statement that is false.
:: So the following section is omitted until the next "[at]end".
:: Note: the "[at]then" does nothing and is only for readablility.
:: Batch Section
@echo off
echo Batch %*
CScript //E:JScript //Nologo "%~f0" %*
echo %ErrorLevel%
pause >nul
exit /b
@end
// JScript Section
try
{
// This will crash if there are no arguments.
WScript.Echo("JScript " + WScript.Arguments.Item(0));
WScript.Quit(7);
}
catch(e)
{
WScript.Quit(1);
}
@if (@X == @Y) @end /*
:: The first line above is...
:: in Batch, a valid IF command that does nothing.
:: in JScript, a conditional compilation IF statement that is false.
:: So the following section is omitted until the close of the comment.
:: Batch Section
@echo off
echo Batch %*
CScript //E:JScript //Nologo "%~f0" %*
echo %ErrorLevel%
pause >nul
exit /b
*/// JScript Section
try
{
// This will crash if there are no arguments.
WScript.Echo("JScript " + WScript.Arguments.Item(0));
WScript.Quit(7);
}
catch(e)
{
WScript.Quit(1);
}
Rem^ &@echo off
Rem^ &goto Batch
' VBScript Section
Function Foo()
WScript.Echo "VBScript"
End Function
Foo
WScript.Quit 7
:Batch
::<NUL>
:: Batch Section
echo Batch %*
CScript //E:VBScript //Nologo "%~f0" %*
echo %ErrorLevel%
pause >nul
exit /b
: Foo : WScript.Quit 6
Rem^ &@echo off
Rem^ &goto Batch
' VBScript Section
Function Foo()
WScript.Echo "VBScript"
End Function
:Batch
::<NUL>
:: Batch Section
echo Batch %*
CScript //E:VBScript //Nologo "%~f0" %*
echo %ErrorLevel%
pause >nul
exit /b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.