1
votes

I am trying to execute a NAnt build script, which is perfectly working in one environment, but recently I have migrated my Build files to a new machine where I am facing the below issue.

NAnt Code Used : exec program="cmd" commandline="/c ${build.dir}\XXX.vbs ${build.version}" failonerror="false"

NAne Error received External Program Failed: cmd (return code was 1)

My Possible tries to overcome this I have checked the environment variables and found that all are fine and also compared with the old machine to match the same.

Any solutions / comments ??

1
What happens if you give the full path to cmd.exe? C:\Windows\system32\cmd.exejohnluetke
@johnluetke > Hmmm..Haven't tried that..Lemme try it ..Thanks :)HARESH KRISHNAN

1 Answers

1
votes

It seems "cmd" is running and you don't need to provide the full path. The error "External Program Failed: cmd (return code was 1)" means the 'cmd' ran but it produced an error. In other words your VB script (i.e. 'XXX.vbs') is failing. Try the following to find the actual error:

  1. Validate that the expanded value of "${build.dir}\XXX.vbs" is a valid file/location. Double check your working directory if you're working with relative paths.

    <echo message="${build.dir}\XXX.vbs" />
    

    or

    <echo message="${file::exists(build.dir + '\XXX.vbs')}" />
    
  2. Run your NAnt script from the command line. This will give you a better error message, like a popup error from Windows Script Host.

    C:\YourTools\NAnt.exe -buildfile:MyBuildScript.build
    

    Avoid the command window, redirect the program's output. Append " >> exec.log" to your commandline string in the 'exec' task, then check the contents of the output/log file (i.e. 'exec.log').

    <exec program="cmd" commandline="/c ${build.dir}\XXX.vbs ${build.version} >> xxx_exec.log" failonerror="false" />
    
  3. Alternatively, a better way to use the 'exec' task is to use nested 'arg' elements. This would help in the case that your arguments have spaces in them; and your script will read clearer:

    <exec program="cmd" failonerror="false">
        <arg value="/c" />
        <arg value="${build.dir}\XXX.vbs" />
        <arg value="${build.version}" />
    </exec>
    
  4. Lastly, in the case your VB script is failing because of invalid arguments (maybe because of spaces in '${build.version}'), use something like the following to debug the VB script:

    WScript.echo "Argument count", wscript.arguments.count
    
    For i = 0 to wscript.arguments.count - 1
        Wscript.Echo wscript.arguments.item(i)
    Next
    

Hope this helps.