0

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

1

1 Answer 1

1

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}`);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.