title: batch file: "2>&1 was unexpected at this time."
body: <p>I've done a ton of searching on this, but none of the answers I've found worked or ended up being relevant. I hope someone can help and I hope this might be a common enough problem to help others.</p>
  
  <p>I've taken a batch file (that worked) and have been reworking it to be better formatted, a bit more structured, etc.... There is a line in the function ":build" that redirects STDERR to STDOUT using the common 2>&amp;1 method in the piping from a command.</p>
  
  <hr>
  
  <pre><code>rem EnableDelayedExpansion
  @echo off
  
  setlocal
  
  rem ##########################################################
  rem NOTE: User should have enviornment variable already set
  rem up for ToolsBasePath to point to the views directory for
  rem US Tools.
  rem ##########################################################
  
  
  rem ##########################################################
  rem Global Setup
  rem ##########################################################
  
  echo Global Setup: Setup enviornment variables used for build script
  
  title Creating Time Stamp
  call :getTS     REM timestamp is now in variable %TIMESTAMP% 
  
  rem This file creates logs either at NBLDir (e.g. c:\_NightlyBuildLogs)
  title Initializing script variables
  set ViewDirC=C:\views
  set NBLDir=C:\_NightlyBuildLogs
  set path=%ToolsBasePath%\stp\bin;C:\Windows\Microsoft.NET\Framework\v4.0.30319;%path%
  set nightlyLog=%NBLDir%\%TIMESTAMP%_nightly.log
  
  REM Initialize all build/update variables to 0
  set update=0
  set rebase=0
  set rebaseComplete=0
  set sync=0
  set sconsClean=0
  set sconsBuild=0
  set cab=0
  
  rem Create header for Nightly Build Log
  echo ######################################################### &gt;&gt;%nightlyLog%
  echo Nightly Build Log &gt;&gt; %nightlyLog%
  time /T  &gt;&gt; %nightlyLog%
  echo ######################################################### &gt;&gt;%nightlyLog%
  echo: &gt;&gt; %nightlyLog%
  echo PATH=%PATH% &gt;&gt; %nightlyLog%
  echo ViewDirC=%ViewDirC% &gt;&gt; %nightlyLog%
  echo ToolsBasePath=%ToolsBasePath% &gt;&gt; %nightlyLog%
  echo NBLDir=%NBLDir% &gt;&gt; %nightlyLog%
  echo: &gt;&gt; %nightlyLog%
  
  
  rem Update US Tools
  title Updating US Tools (~10 minutes)
  echo Update US Tools (~10 minutes)  
  time /t
  echo Update US Tools &gt;&gt; %nightlyLog%
  time /T  &gt;&gt; %nightlyLog%
  echo ######################################################### &gt;&gt;%nightlyLog%
  rem Comment this out for now just to skip it to test the build portion
  rem call cchar_EWS_updateUSTools.cmd %TIMESTAMP%
  echo Update of US Tools Complete &gt;&gt; %nightlyLog%
  time /T  &gt;&gt; %nightlyLog%
  time /t
  echo:
  
  title Building V2016 (~60 minutes) 
  echo Build V2016 (~60 minutes) 
  echo Build V2016 (~60 minutes) &gt;&gt; %nightlyLog%
  time /T
  time /T  &gt;&gt; %nightlyLog%
  echo ######################################################### &gt;&gt; %nightlyLog%
  call :BuildV2016
  echo Build of V2016 Complete &gt;&gt; %nightlyLog%
  time /T  &gt;&gt; %nightlyLog%
  time /T
  echo:
  
  
  rem END of Main()
  goto :end
  
  
  :BuildV2016
  cd /d %ViewDirC%\cchar_V2016DEV_EWS
  
  rem Base ClearCase Settings
  set update=0
  
  rem UCM ClearCase Settings
  set rebase=0
  set rebaseComplete=0
  
  rem Note: sync is like update, only really beneficial if others are
  rem delivering to your stream or you are working on more than one view.
  set sync=0
  
  rem SCons Builds Settings
  set sconsClean=0
  set sconsBuild=1
  set cab=1
  
  echo Starting Build of V2016 &gt;&gt; %nightlyLog%
  call :build
  exit /b
  
  
  rem ##########################################################
  rem Build section, recommend you make no modifications below here.
  rem ##########################################################
  goto :end
  
  :build
  echo ######################################################### &gt;&gt; %nightlyLog%
  echo Building/Updating from %cd%
  echo Building/Updating from %cd% &gt;&gt; %nightlyLog%
  time /T  &gt;&gt; %nightlyLog%
  time /T
  
  echo rebase=%rebase% &gt;&gt; %nightlyLog%
  echo sync=%sync% &gt;&gt; %nightlyLog%
  echo update=%update% &gt;&gt; %nightlyLog%
  echo sconsClean=%sconsClean% &gt;&gt; %nightlyLog%
  echo sconsBuild=%sconsBuild% &gt;&gt; %nightlyLog%
  echo cab=%cab% &gt;&gt; %nightlyLog%
  
  set vgr=1
  set qlab=0
  if %vgr% == 1 set buildDir=vgrDevEnv\build\
  if %qlab% == 1 set buildDir=QlabCore\build\
  
  if %rebaseComplete% == 1 (
    set rebase=1
    set rebaseOptions=-complete
    ) else ( set rebaseOptions= )
  
  
  rem Perform Rebase
  set rebaseLog=%NBLDir%\%TIMESTAMP%_rebase.log
  if %rebase% == 1 (
    echo rebaseLog=%rebaseLog% &gt;&gt; %nightlyLog%
    set update=0
    set sync=0
    echo Rebasing %rebaseLog% &gt;&gt; %nightlyLog%
    cleartool rebase -rec %rebaseOptions% -force -abort &gt;&gt; %rebaseLog% 2&gt;&amp;1
    )
  
  if %sync% == 1 (
    echo Syncing... &gt;&gt; %nightlyLog%
    cleartool setcs -stream
    )
  
  if %update% == 1 (
    echo Updating %cd%... &gt;&gt; %nightlyLog%
    cleartool setcs -current
    )
  
  rem Build SCONS
  if %sconsClean% == 1 sconsCount.exe -clean &gt;&gt; %nightlyLog% 2&gt;&amp;1
  
  if %sconsBuild% == 1 (
    set buildLog=%NBLDir%\%TIMESTAMP%_build.log
    echo buildLog=%buildLog% &gt;&gt; %nightlyLog%
    echo Building SCons %buildLog% &gt;&gt; %nightlyLog%
    call %buildDir%scons.bat -k &gt; %buildLog% 2&gt;&amp;1
    sconsCount.exe &gt;&gt; %buildLog% 2&gt;&amp;1
    wxsMissingFileTest &gt;&gt; %buildLog%
    SConsBuildReport %buildLog% &gt;&gt; %nightlyLog%
    )
  
  REM Build Cabs  
  if %cab% == 1 (
    set cabLog=%NBLDir%\%NBLDir%\%TIMESTAMP%_cab.log
    echo cabLog=%cabLog% &gt;&gt; %nightlyLog%
    echo Creating CAB files &gt;&gt; %nightlyLog%
    call %buildDir%cabs.bat &gt;&gt; %cabLog%
    )
  
  rem exit from :Build
  
  exit /b
  
  
  :getTS
  REM Slice the %date% string to get date parts
  set tsyear=%date:~-4% 
  set tsmonth=%date:~4,2% 
  set tsday=%date:~7,2% 
  
  REM Put date parts together, subtituting "" for the " " because for
  REM some reason the shell adds a space to each variable.
  set TSDATE=%tsyear: =%%tsmonth: =%%tsday: =%
  
  REM Slice the %time% string to get time parts
  set tshour=%time:~0,2%
  set tsminute=%time:~3,2%
  set tsseconds=%time:~6,2%
  set tsmilliseconds=%time:~-2%
  
  REM Put time parts together, subtituting "" for the " " because for
  REM some reason the shell adds a space to each variable.
  set TSTIME=%tshour: =%%tsminute: =%%tsseconds: =%%tsmilliseconds: =%
  
  set TIMESTAMP=%TSDATE%%TSTIME%
  exit /b
  
  
  :end
  echo ######################################################### &gt;&gt; %nightlyLog%
  echo Build(s) completed &gt;&gt; %nightlyLog%
  time /T  &gt;&gt; %nightlyLog%
  endlocal
  </code></pre>
  
  <hr>
  
  <p>The line in question is:
    cleartool rebase -rec %rebaseOptions% -force -abort >> %rebaseLog% 2>&amp;1</p>
  
  <p>This is in the "if %rebase%" block, which ironically isn't even being called. I'm guessing it's failing just during the parse.</p>
  
  <p>Can anyone see why this might be giving me the "2>&amp;1 was unexpected at this time." error?</p>