Last active
November 13, 2024 13:00
-
-
Save davidruhmann/5199433 to your computer and use it in GitHub Desktop.
[Batch] JScript and Batch Hybrid
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 (@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); | |
} |
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 (@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); | |
} |
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
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