dawidklos
dawidklos

Reputation: 922

Executing node script with custom arguments

I have node.js script, that uses -b arg1 and --parameter arg2 arguments. Is there any method do pass them with Grunt task?

I have tried grunt-execute,

execute: {
            options: {
                args :['-b test']
            },
            target: {
                src: ['uploader.js']
            }
        },

But there was always space before test

Upvotes: 1

Views: 541

Answers (1)

scthi
scthi

Reputation: 2481

You can use execSync directly:

var cmd = 'node uploader.js -b arg1 --parameter arg2';
var opts = { cwd: process.cwd() };
var result = require('child_process').execSync(cmd, opts).toString().trim();

see: https://nodejs.org/api/child_process.html#child_process_child_process_execsync_command_options

Upvotes: 1

Related Questions