Question

I'm trying to use jsmin with nant - and it just uses stdin and stdout for input and output. The nant 'exec' task allows you to redirect the output to a file, but not get the input from a file.

I have tried with a 'commandline' using '>' and '<' to direct the input and output, but nant just goes away and doesn't come back :(

I can't believe no-one's tried to do this before. Please help! :)

Was it helpful?

Solution

From http://www.mail-archive.com/nant-developers@lists.sourceforge.net/msg04575.html. You should be able to do something similar to:

        <exec program="cmd.exe" workingdir=".">
                <arg value="/c cacls" />
                <arg value="${mdb.file}" />
                <arg value="/E" />
                <arg value="/G testpc\aspnet:F" />
                <arg value="&lt; y.txt" />
        </exec>

OTHER TIPS

I believe NAnt does support input from a file. Since the build file is XML you must use the xml encoded "<".

<exec program="somefile.exe" workingdir=".">
  <arg value="&lt; input.txt" />
</exec>

The redirect and pipe operators are an feature of the shell, C and C# support redirection by other means (file handles). Somewhere I read that because the C# Process class did not support input redirection, nant provides only output redirection for <exec>.

To redirect command input we can resort to the shell:

A) Invoking cmd.exe with /c as shown in the example of acloutier above. Care must be taken with whitespaces! Actually the example fails due to the space between < and y.txt, remove it to make the example work. You can can also convert the value attribute in a line attribute but then you have to be careful with quoting.

B) Since I could not get pipes to work using the exec-cmd approach, instead I am generating a batch-file on the fly using <echo>:

<echo file="${WD}/login.bat">"${P4}" diff -sd | "${P4}" -x- sync -f using</echo>        
<exec program="login.bat" basedir="${WD}" workingdir="${P4.WorkspaceRoot}" />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top