jscript
JScript runner: a duplex stream wrapper around cscript with optional JSON serialization for easy marshalling of data between Node.js and Windows Script Host.
example
Let's create a version.js
: a JScript that reads the FileVersion
of executables.
var JSON = var fs = 'Scripting.FileSystemObject' while!WScriptStdInAtEndOfStream var file = JSON if fs fileversion = fs WScriptStdOut
Install this script's dependencies and create a bundle with jscriptify:
npm install json3npm install -g jscriptifyjscriptify version.js > bundle.js
Last but not least, an example.js
:
var jscript = var path = var duplex = duplex processargv duplex
And run it with Node.js:
> node example one.exe two.exe 16.4.86.2.3
Note: avoid StdOut.WriteLine()
because json-stream
doesn't like CRLF.
jscript(file, [opts])
- file: relative or absolute path to a JScript file.
Options:
- args (array): script arguments
- json (boolean): if true, wrap stream with JSON serialization
- debug (boolean): if true, pipe stderr to process.stderr;
- native: if false, don't escape WoW64 redirection (passed to windows-bin).
install
With npm do:
npm install jscript
changelog
2.0.0
- Drop support of Node 0.10 and 0.12, and 6 and 7
- Emit error on non-zero exit code;
- Remove
wrap
option. Use{ json: true }
instead.
license
MIT © Vincent Weevers