Skip to content

Instantly share code, notes, and snippets.

@rmckeel
Last active August 9, 2021 23:37
Show Gist options
  • Save rmckeel/b4e60922f5098ced9c50bdd96731b34a to your computer and use it in GitHub Desktop.
Save rmckeel/b4e60922f5098ced9c50bdd96731b34a to your computer and use it in GitHub Desktop.
Gulp no-dependency spawn / execute a file with live stdout feedback
const gulp = require( 'gulp' );
const spawn = require( 'child_process' ).spawn;
/**
* This solution to execute and watch a shell function from Gulp is
* adapted from https://stackoverflow.com/a/10232330/3232832
*
* e.g. callSpawn( 'ping', [ '-c 5', 'google.com' ], cb );
*/
function callSpawn( command, arguments, cb ) {
const call = spawn( command, arguments, { stdio : 'inherit' } );
call.on( 'exit', function ( code ) {
console.log( 'child process exited with code ' + code.toString() );
cb();
} );
}
gulp.task( 'test:ping', function ( cb ) {
callSpawn( 'ping', [ '-c 10', 'google.com' ], cb );
} )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment