tags:

views:

89

answers:

2

I am calling a batch file inside a nant script and would like to get the value ( a string of 5 characters) return back to the nant script and continue the nant script. Please suggest how this can be done. Thanks in advance.

+1  A: 

I don't know nant at all, but the most common way for a batch file to return data is the ERRORLEVEL. However, the errorlevel is numeric only (1-255) AFAIK. To return an errorlevel, use EXIT in your batch file:

EXIT 1

The second way would be making your batch file output the value ... Very risky though, as other output might interfere with it.

The third way would be writing the result out in a file (e.g. "call command > result.txt") and have nant parse the file.

In each case, you have to make nant parse the result - which way is the most feasible depends on what it can deal with.

Pekka
A: 

You could use the resultproperty attribute of the exec task node

Your batch file (foo.bat):

...
@exit 101

Your NAnt code snippet:

<exec
  program="C:\foo.bat"
  resultproperty="bar"
  failonerror="false" />
<echo message="batch returned ${bar}"/>
The Chairman