Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Edited bit >> tldr; No, you can't.</p> <p>I try to explain the redirection a bit.</p> <p>You redirect one of the ten streams with <strong>> file</strong> or <strong>&lt; file</strong><br> It is unimportant, if the redirection is before or after the command, so these two lines are nearly the same.</p> <pre><code>dir &gt; file.txt &gt; file.txt dir </code></pre> <p>The redirection in this example is only a shortcut for <strong>1></strong>, this means the stream 1 (STDOUT) will be redirected.<br> So you can redirect any stream with prepending the number like <strong>2> err.txt</strong> and it is also allowed to redirect multiple streams in one line.</p> <pre><code>dir 1&gt; files.txt 2&gt; err.txt 3&gt; nothing.txt </code></pre> <p>In this example the "standard output" will go into files.txt, all errors will be in err.txt and the stream3 will go into nothing.txt (DIR doesn't use the stream 3).<br> <strong>Stream0 is STDIN<br> Stream1 is STDOUT<br> Stream2 is STDERR<br> Stream3-9 are not used</strong></p> <p>But what happens if you try to redirect the same stream multiple times?</p> <pre><code>dir &gt; files.txt &gt; two.txt </code></pre> <p>"There can be only one", and it is always the last one!<br> So it is equal to <strong>dir > two.txt</strong></p> <p>Ok, there is one extra possibility, redirecting a stream to another stream.</p> <pre><code>dir 1&gt;files.txt 2&gt;&amp;1 </code></pre> <p><strong>2>&amp;1</strong> redirects stream2 to stream1 and <strong>1>files.txt</strong> redirects all to <strong>files.txt</strong>.<br> The order is important here!</p> <pre><code>dir ... 1&gt;nul 2&gt;&amp;1 dir ... 2&gt;&amp;1 1&gt;nul </code></pre> <p>are different. The first one redirects all (STDOUT and STDERR) to NUL,<br> but the second line redirects the STDOUT to NUL and STDERR to the "empty" STDOUT.</p> <p>As one conclusion, it is obvious why the examples of Otávio Décio and andynormancx can't work.</p> <pre><code>command &gt; file &gt;&amp;1 dir &gt; file.txt &gt;&amp;2 </code></pre> <p>Both try to redirect stream1 two times, but "There can be only one", and it's always the last one.<br> So you get</p> <pre><code>command 1&gt;&amp;1 dir 1&gt;&amp;2 </code></pre> <p>And in the first sample redirecting of stream1 to stream1 is not allowed (and not very useful).</p> <p>Hope it helps. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload