jscript

2.0.0 • Public • Published

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.

npm status AppVeyor build status Dependency status

example

Let's create a version.js: a JScript that reads the FileVersion of executables.

var JSON = require('json3')
var fs = new ActiveXObject('Scripting.FileSystemObject')
 
while(!WScript.StdIn.AtEndOfStream) {
  var file = JSON.parse(WScript.StdIn.ReadLine())
 
  if (fs.FileExists(file.path)) {
    file.version = fs.GetFileVersion(file.path)
  }
 
  WScript.StdOut.Write(JSON.stringify(file) + '\n')
}

Install this script's dependencies and create a bundle with jscriptify:

npm install json3
npm install -g jscriptify
jscriptify version.js > bundle.js

Last but not least, an example.js:

var jscript = require('jscript')
var path = require('path')
var duplex = jscript('bundle.js', { json: true })
 
duplex.on('data', function(file) {
  console.log(file.version)
})
 
process.argv.slice(2).forEach(function (file) {
  duplex.write({ path: path.resolve(file) })
})
 
duplex.end()

And run it with Node.js:

> node example one.exe two.exe
 
16.4.8
6.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

Package Sidebar

Install

npm i jscript

Weekly Downloads

9

Version

2.0.0

License

MIT

Last publish

Collaborators

  • vweevers