title: How to use Windows CMD pipe( | ) feature with CALL :Label command option?
body: <p>I have a frustrating problem when I want to use the pipe(<strong>|</strong>) feature with the Window's CMD shell's <strong>CALL :Label</strong> option.  I have a very small example (below): <strong>call-test</strong>.cmd and sample output.</p>
  
  <p>The nub of the issue was/is to pipe the output of a CMD script to another program, for example the <strong>tee</strong> utility, or <strong>find</strong> command.  For example:</p>
  
  <pre><code>    @call   :Label-02  param  | tee call-test.log
  </code></pre>
  
  <p>Which would start the current command file at the label <strong>Label-02</strong> and pipe the output to <strong>tee</strong>.  Unfortunately using the pipe character(|) on the line with "call :label" option gives an error:</p>
  
  <pre><code>Invalid attempt to call batch label outside of batch script.
  </code></pre>
  
  <p>Whereas, "<strong>call  example.cmd</strong> | tee example.log", works just fine.</p>
  
  <p>The other IO redirection <strong>></strong> works OK.  It is just the one case when "<strong>call :label pipe(|)</strong>" is used that fails.  To me it just looks like a windows bug.</p>
  
  <p>Does anyone have a workaround and/or know of an explanation?  </p>
  
  <p>Thanks,
           Will</p>
  
  <hr>
  
  <ul>
  <li><p><strong>call-test output</strong></p>
  
  <pre><code>c:\&gt; call-test
      [start]
      label 03 :: p1
  Invalid attempt to call batch label outside of batch script.
  Invalid attempt to call batch label outside of batch script.
      [done]
  Press any key to continue . . .
  </code></pre></li>
  <li><p><strong>call-test</strong></p>
  
  <pre><code>@echo off 
  @rem   call-test.cmd
  @rem  _________________________________________________
  @rem    Test :label call option for .cmd files.
  @rem
  @echo   ^  [start]
  @call   :Label-03  p1
  @call   :Label-02  second  | find " "
  @call   :Label-02  second  | tee call-test.log
  @goto   Done
  @rem  _________________________________________________
  :Label-01 
  @echo   ^  label 01 :: %1
  @goto Exit
  @rem  _________________________________________________
  :Label-02 
  @echo   ^  label 02 :: %1
  @goto Exit
  @rem  _________________________________________________
  :Label-03 
  @echo   ^  label 03 :: %1
  @goto Exit
  @rem  _________________________________________________
  :Done 
  @echo   ^  [done]
  @pause
  @rem  _________________________________________________
  :Exit 
  @exit /b
  </code></pre></li>
  </ul>