Git Product home page Git Product logo

node-shell-parser's Introduction

From shell output to json

Converts the usual, space separated, table from a shell command into a list of json object where the keys are the columns' names and the values the different data for each row.

Install

You can install this library through NPM:

npm install node-shell-parser

Definition:

  shellParser(shellOutput, options);
  • shellOutput: the string resulting from running your command
  • options.separator: which character separates your tabled data, default is one space
  • options.skipLines: how many lines to skip before meeting the columns definition header

Usage

Execute a process, get its output and then simply feed it to the parser:

var shellParser = require('node-shell-parser');
var child = require('child_process');

var process = child.spawn('ps');
var shellOutput = '';

process.stdout.on('data', function (chunk) {
  shellOutput += chunk;
});

process.stdout.on('end', function () {
  console.log(shellParser(shellOutput))
});

Black magic in action:

~/projects/namshi/node-shell-parser (master ✘)✭ ᐅ node test.js
[ { PID: '729', TTY: 'pts/1    00:0', TIME: '0:00', CMD: 'zsh' },
  { PID: '057', TTY: 'pts/1    00:0', TIME: '0:00', CMD: 'node' },
  { PID: '059', TTY: 'pts/1    00:0', TIME: '0:00', CMD: 'ps' } ]

node-shell-parser's People

Contributors

unlucio avatar fmalekpour avatar framp avatar odino avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.