Last active
August 9, 2021 23:37
-
-
Save rmckeel/b4e60922f5098ced9c50bdd96731b34a to your computer and use it in GitHub Desktop.
Gulp no-dependency spawn / execute a file with live stdout feedback
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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