RyanCW RyanCW - 3 years ago 154
Groovy Question

How to call npm external command from Groovy?

I am trying to run an external command in groovy. But I am getting a

Caught: java.io.IOException: Cannot run program "npm install":
CreateProcess error=2, The system cannot find the file specified.

I am new to Groovy so any suggestions would be greatly appreciated. Also my path is set since I am able to run npm in command line.

def command = "npm install"
def proc = command.execute()
println "This is output: " + proc?.err?.text

Answer Source

If you are running on windows try:

['cmd', '/c', 'npm', 'install'].execute()

Also it's good practice to use List.execute() than String.execute().

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download