Browse Source

Avoid "useless use of cat" award by using a real world example.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@275094 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 22 years ago
parent
commit
e3df11cc0a
2 changed files with 20 additions and 18 deletions
  1. +10
    -9
      docs/faq.html
  2. +10
    -9
      xdocs/faq.xml

+ 10
- 9
docs/faq.html View File

@@ -673,26 +673,27 @@
How do I redirect standard input or standard output How do I redirect standard input or standard output
in the <code>&lt;exec&gt;</code> task? in the <code>&lt;exec&gt;</code> task?
</p> </p>
<p>Say you want to redirect the standard input stream of the
<code>cat</code> command to read from a file, something
<p>Say you want to redirect the standard output stream of the
<code>m4</code> command to write to a file, something
like:</p> like:</p>
<pre class="code"> <pre class="code">
shell-prompt&gt; cat &lt; foo
shell-prompt&gt; m4 foo.m4 &gt; foo
</pre> </pre>
<p>and try to translate it into</p> <p>and try to translate it into</p>
<pre class="code"> <pre class="code">
&lt;exec executable=&quot;cat&quot;&gt;
&lt;arg value=&quot;&amp;lt;&quot; /&gt;
&lt;arg value=&quot;foo&quot; /&gt;
&lt;exec executable=&quot;m4&quot;&gt;
&lt;arg value=&quot;foo.m4&quot;/&gt;
&lt;arg value=&quot;&amp;gt;&quot;/&gt;
&lt;arg value=&quot;foo&quot;/&gt;
&lt;/exec&gt; &lt;/exec&gt;
</pre> </pre>
<p>This will not do what you expect. The input redirection is
<p>This will not do what you expect. The output redirection is
performed by your shell, not the command itself, so this performed by your shell, not the command itself, so this
should read:</p> should read:</p>
<pre class="code"> <pre class="code">
&lt;exec executable=&quot;/bin/sh&quot;&gt; &lt;exec executable=&quot;/bin/sh&quot;&gt;
&lt;arg value=&quot;-c&quot; /&gt; &lt;arg value=&quot;-c&quot; /&gt;
&lt;arg value=&quot;cat &amp;lt; foo&quot; /&gt;
&lt;arg value=&quot;m4 foo.m4 &amp;gt; foo&quot; /&gt;
&lt;/exec&gt; &lt;/exec&gt;
</pre> </pre>
<p>Note that you must use the <code>value</code> attribute of <p>Note that you must use the <code>value</code> attribute of
@@ -701,7 +702,7 @@ shell-prompt&gt; cat &lt; foo
you can use:</p> you can use:</p>
<pre class="code"> <pre class="code">
&lt;exec executable=&quot;/bin/sh&quot;&gt; &lt;exec executable=&quot;/bin/sh&quot;&gt;
&lt;arg line='-c &quot;cat &amp;lt; foo&quot;'/&gt;
&lt;arg line='-c &quot;m4 foo.m4 &amp;gt; foo&quot;'/&gt;
&lt;/exec&gt; &lt;/exec&gt;
</pre> </pre>
<p>Note the double-quotes nested inside the single-quotes.</p> <p>Note the double-quotes nested inside the single-quotes.</p>


+ 10
- 9
xdocs/faq.xml View File

@@ -313,31 +313,32 @@
<question>How do I redirect standard input or standard output <question>How do I redirect standard input or standard output
in the <code>&lt;exec&gt;</code> task?</question> in the <code>&lt;exec&gt;</code> task?</question>
<answer> <answer>
<p>Say you want to redirect the standard input stream of the
<code>cat</code> command to read from a file, something
<p>Say you want to redirect the standard output stream of the
<code>m4</code> command to write to a file, something
like:</p> like:</p>


<source><![CDATA[ <source><![CDATA[
shell-prompt> cat < foo
shell-prompt> m4 foo.m4 > foo
]]></source> ]]></source>
<p>and try to translate it into</p> <p>and try to translate it into</p>


<source><![CDATA[ <source><![CDATA[
<exec executable="cat">
<arg value="&lt;" />
<arg value="foo" />
<exec executable="m4">
<arg value="foo.m4"/>
<arg value="&gt;"/>
<arg value="foo"/>
</exec> </exec>
]]></source> ]]></source>


<p>This will not do what you expect. The input redirection is
<p>This will not do what you expect. The output redirection is
performed by your shell, not the command itself, so this performed by your shell, not the command itself, so this
should read:</p> should read:</p>
<source><![CDATA[ <source><![CDATA[
<exec executable="/bin/sh"> <exec executable="/bin/sh">
<arg value="-c" /> <arg value="-c" />
<arg value="cat &lt; foo" />
<arg value="m4 foo.m4 &gt; foo" />
</exec> </exec>
]]></source> ]]></source>


@@ -347,7 +348,7 @@ shell-prompt> cat < foo
you can use:</p> you can use:</p>
<source><![CDATA[ <source><![CDATA[
<exec executable="/bin/sh"> <exec executable="/bin/sh">
<arg line='-c "cat &lt; foo"'/>
<arg line='-c "m4 foo.m4 &gt; foo"'/>
</exec> </exec>
]]></source> ]]></source>




Loading…
Cancel
Save