fm-exec

Helper to spawn external applications

Usage no npm install needed!

<script type="module">
  import fmExec from 'https://cdn.skypack.dev/fm-exec';
</script>

README

fm-exec

Coverage Status Code Climate GitHub license

What?

Helper to spawn external applications.

  • uses child_process.spawn() by default (using the shell is also possible, with exec.shell)
  • uses promises
  • allows you to use the same signature for spawn and exec calls
  • conveniently buffers process output, if desired

How?

Install

npm install fm-exec

Usage

var exec = require( "fm-exec" );

// Just run a binary. Returns a promise.
exec( "notepad" );

// Run a binary with arguments.
exec( "notepad", [ "foo.txt" ] );

// Buffer application output to receive it in resolution/rejection handler.
exec( "git", [ "rev-parse", "HEAD" ], {
    cwd    : applicationDirectory,
    buffer : true
} )
    .then( function echoVersion( version ) {
        console.log( version );
    } )
    .catch( function onError( error ) {
        // handle error
    } );

// Execute a command through the shell.
exec.shell( "notepad", [ "foo.txt" ] );
// When using exec.shell, this call is identical to the one above.
exec.shell( "notepad foo.txt" );