jharding / grunt-exec

Grunt plugin for executing shell commands.
https://npmjs.org/package/grunt-exec
Other
248 stars 47 forks source link

Please use grunt.util.spawn #46

Closed stevenvachon closed 7 years ago

stevenvachon commented 10 years ago

It uses child_process.spawn() which preserves stdout/stderr colors.

If you'd rather use Node's API directly, here's how I'm currently doing it:

var child = child_process.spawn(app, [command], {cwd:cwd, stdio:"inherit"});

child.on("exit", function(code)
{
    this.removeAllListeners();

    callback();
});
Furchin commented 10 years ago

+1

jharding commented 10 years ago

If somebody posts a pull request, I'll accept it.

dandv commented 10 years ago

There's already a grunt-spawn plugin.

stevenvachon commented 10 years ago

grunt-spawn does not have stdio:"inherit". Instead, it appears to have a bunch of over-complication.

dandv commented 10 years ago

Hey @fir3pho3nixx, see above.

ghost commented 10 years ago

grunt-spawn has it's own file pattern matching code because when I started out, I quickly found that ant style wildcards and file scanning were not something that was easy to come by, rather than succumb to using regex I opted for roll-my-own. Hence all the carry on :)

If you are after the ability to make stdio: "inherit", you can do this with grunt-spawn today.

It accepts an opts parameter:

opts: { cwd: process.cwd() } -> Pass through mechanism for passing 'opts' to grunt.util.spawn. As long as the 'dontWait' flag is set to false.

This parameter is delegated down to grunt.util.spawn, which in turn would become the opts for the nodejs spawn.

*\ snippet from: http://gruntjs.com/api/grunt.util

grunt.util.spawn

Spawn a child process, keeping track of its stdout, stderr and exit code. The method returns a reference to the spawned child. When the child exits, the doneFunction is called.

grunt.util.spawn(options, doneFunction) The options object has these possible properties:

var options = { // The command to execute. It should be in the system path. cmd: commandToExecute, // If specified, the same grunt bin that is currently running will be // spawned as the child command, instead of the "cmd" option. Defaults // to false. grunt: boolean, // An array of arguments to pass to the command. args: arrayOfArguments, // Additional options for the Node.js child_process spawn method. opts: nodeSpawnOptions, // If this value is set and an error occurs, it will be used as the value // and null will be passed as the error value. fallback: fallbackValue };

* snippet end *

@stevenvachon - Comments taken on board. Will add milestone to make the code more 'obvious'. Parameters are slightly obfuscated in their current form.

gwicksted commented 7 years ago

Upcoming version using child_process.spawn instead of child_process.exec.