Skip to content

Instantly share code, notes, and snippets.

@davidruhmann
Last active November 13, 2024 13:00
Show Gist options
  • Save davidruhmann/5199433 to your computer and use it in GitHub Desktop.
Save davidruhmann/5199433 to your computer and use it in GitHub Desktop.
[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