small medium large xlarge

20 Jun 2017, 02:59
Isaac Allen (1 post)

Hello! I’m a little stumped on figuring out how one would “pass an arbitrary number of additional parameters from process.argv to the spawned process (e.g., node –harmony watcher-hw.js ls -l -h)” I guess because the (e.g.) only mentions one file. Putting this into the original watcher-spawn.js returns Error: watch ls is ENOENT. Forgive me I’m really new, and I’m sure the answer is much more obvious than I think it is.

27 Jun 2017, 10:06
Jim R. Wilson (92 posts)

Hi Isaac,

Thanks for taking the time to post! I admit that question is pretty cryptic.

All I meant was that I wanted you to think about how you’d deal with an argv that had an unpredictable number of elements.

In JavaScript, you can copy a portion of an array using the slice() method.

const original = ['a', 'b', 'c'];
const part = original.slice(1);  // Contains ['b', 'c'], original is unchanged.

Considering the interplay between the Node.js program’s argv array, and the arguments you pass to spawn(), you could forward an arbitrary number of command line arguments like this:

const child = spawn(progess.argv[2], process.argv.slice(3));
You must be logged in to comment