Question: When I try to run the following Ant script, which executes the **"npm"** command:

```
<target name ="test">
    <exec executable="npm" failonerror="true">
        <arg value="install" />
    </exec>
</target>

```

It fails with this error:

```
Execute failed: java.io.IOException: Cannot run program "npm" 
(in directory "C:\Development\workspace\traqpath\WebSource"): 
CreateProcess error=2, The system cannot find the file specified

```

The same happens when I try to run the Angular-CLI **"ng"** command:

```
<target name ="test">
        <exec executable="ng" failonerror="true">
            <arg value="build"/>
            <arg value="--prod"/>
            <arg value="--bh"/>
        </exec>
</target>

```

With the same error message, but for "ng":

```
Execute failed: java.io.IOException: Cannot run program "ng" 
(in directory "C:\Development\workspace\traqpath\WebSource"): 
CreateProcess error=2, The system cannot find the file specified

```

Both commands run without problems in the Windows Command Line, which means NodeJS installation is right, and NodeJS path is properly configured in the PATH system variable.

Answer: 
I solved it similar to your solution, except I invoked "npm build" which is included by default in the package.json under "scripts" section.

```
<target name="build_windows">
  <exec executable="npm.cmd" failonerror="true">
    <arg value="run-script"/>
    <arg value="build"/>
  </exec>
</target>

```

I even introduced another npm script line similar to "build" named "buildprod" like this:

```
"scripts": {
  "build": "ng build -bh /context/",
  "buildprod": "ng build --prod --aot -bh /context/"
}

```

And then introduced a similar target in my ant build.xml file for the production build something like this:

```
<target name="build_prod_windows">
  <exec executable="npm.cmd" failonerror="true">
    <arg value="run-script"/>
    <arg value="buildprod"/>
  </exec>
</target>

```

That way, you can keep the same ant script in other angular projects, and don't have to worry about keeping different arguments in your build.xml file. Instead, you'll need to ensure your package.json has correct scripts.
```
<target name ="test">
        <exec executable="ng" failonerror="true">
            <arg value="build"/>
            <arg value="--prod"/>
            <arg value="--bh"/>
        </exec>
</target>

```

When i try to run in linux , its again give the same error, saying 
Execute failed: java.io.IOException: Cannot run program "ng" ....

How to run in linux env through ANT