Skip to content

Instantly share code, notes, and snippets.

@fliedonion
Last active October 9, 2015 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fliedonion/4c70ebc8897c0fc3618b to your computer and use it in GitHub Desktop.
Save fliedonion/4c70ebc8897c0fc3618b to your computer and use it in GitHub Desktop.
allow you to write script in windows bat file

this is currently experimental

Summary Shabang.bat allow you to embed your script in bat file. Only put #!.bat.
You can write single script file and #!.bat doesn't create any filein your %temp% to run script
Env Windows and ( node.js or python or ... )
@set scriptEngine=%1
@set scriptEngine=%scriptEngine:/= %
@set scriptEngine=%scriptEngine:\= %
@for %%A in (%scriptEngine%) do @set scriptEngineName=%%A
@echo %scriptEngineName%
@if exist %3 @set scriptName=%3
@if exist %2 @set scriptName=%2
@if "%scriptEngineName%" == "node" (
@goto :node
) else ^
if "%scriptEngineName%" == "python" (
@goto :python
) else (
@echo unknown script engine %scriptEngineName%
@exit /b 1
)
:node
@node %scriptName%
@exit /b %ERRORLEVEL%
@goto :EOF
:python
@python %scriptName%
@exit /b %ERRORLEVEL%
@goto :EOF
@rem README.md
@rem # How to use
@rem * put this file under PATH env as `#!.bat`
@rem * write your script like below with `.bat` or `.cmd` extension:
@rem #! /usr/local/env/node "%~f$PATH:0" "%~f0" %* ^
@rem console.log(process.argv)
@rem * note: also use `\` as script path like `c:\usr\local\env\node`

this is currently experimental

shebang.bat

Write your LL Scripts in .bat or .cmd file.

important notice: Other unix like environment may use similar tricks.

How to use

  • put #!.bat file under PATH env as #!.bat
  • write your script like below with .bat or .cmd extension: #! /usr/local/env/node "%~f$PATH:0" "%~f0" %* ^ console.log(process.argv)
    • note: also use \ as script path like c:\usr\local\env\node
#! c:\usr\local/env\python "%~f$PATH:0" "%~f0" %* ^
print "Hello, World"
#! c:\usr\local/env\node "%~f$PATH:0" "%~f0" %* ^
/*
echo "Hello, World"
*/
console.log(process.argv)
sample space include node-js.cmd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment