Reputation: 1
I am trying to run a shell script inside node.js
using shelljs
module as follows.
exec('mycommand arg1')
where arg1 is supposed to be an Integer. When I replace arg1 with a number (let's say 8) it works perfectly but when I replace arg1 with a variable containing the corresponding value (in that case 8) i get an error with invalid argument.
I tried to do some encoding but it doesn't seem to work. I don t know why. please help
Upvotes: 0
Views: 606
Reputation: 655
I guess you just replaced the arg1 with your variable name, you'll have to concatenate your variable.
var myArg = 8;
exec('mycommand ' + myArg);
If you're using ES6, you can also make use of template literals
var myArg = 8;
exec(`mycommand ${myArg}`);
Upvotes: 1