windows - Batch STDOUT / STDERR redirection weirdness -
i'm running strange issue batch scripts , redirection logs while trying run scripts during provisioning phase of windows 2012r2 system.
the general flow this:
execute init.cmd:
init.cmd:
@echo off echo init - foo call start.cmd >start.log 2>&1 echo init - bar
start.cmd:
@echo off echo start - foo call test1.cmd >test1.log 2>&1 echo start - bar call test2.cmd >test2.log 2>&1 echo start - baz
test1.cmd
@echo off echo hello
test2.cmd
@echo off echo aloha
what happens start.log looks like:
start - foo
then test1.log looks like:
hello start - bar
and test2.log looks like:
aloha start - baz init - bar
basically, appears once redirect stdout/stderr, redirects everything, until redirect elsewhere, @ point, goes new place. i've tried several ways of doing redirection, calling subroutines call :test1 >test1.log 2>&1
, directing those, or wrapping in >start.log 2>&1 (commands)
, of same thing.
i put these sample scripts on windows 10 box though, , worked fine.
is there i'm missing here?
edit:
here's real scripts:
init.cmd:
@echo off md %systemdrive%\logs curl -sf -o %systemroot%\temp\win_installer.cmd http://10.6.7.20/cblr/svc/op/script/system/acme.example.com/?script=win_installer.cmd call %systemroot%\temp\win_installer.cmd >%systemdrive%\logs\installer.log 2>&1 if errorlevel 1 ( echo installer failed goto:eof ) shutdown /r /t 0
win_installer.cmd:
@echo off setlocal enabledelayedexpansion echo mounting samba share winlogs l: net use l: \\10.6.7.20\winlogs if exist "l:" ( md l:\example.acme.com ) echo beginning run stage call :run if errorlevel 1 ( echo win2012r2.cmd failed run goto :err ) echo run stage completed if not exist "l:\example.acme.com" ( echo failed create l:\example.acme.com echo isn't fatal, going continue echo logs still kept locally ) echo copying setupact.log copy %systemroot%\panther\setupact.log l:\acme.example.com echo copying setuperr.log copy %systemroot%\panther\setuperr.log l:\acme.example.com echo copying %systemdrive%\logs\win2012r2.log copy %systemdrive%\logs\win2012r2.log l:\acme.example.com echo beginning netconf stage call :netconf if errorlevel 1 ( echo not configure network goto :err ) echo netconf stage completed goto :end :run echo downloading install script win2012r2.cmd echo curl -sf -o %systemroot%\temp\win2012r2.cmd http://10.6.7.20/cblr/svc/op/script/system/acme.example.com/?script=win2012r2.cmd curl -sf -o %systemroot%\temp\win2012r2.cmd http://10.6.7.20/cblr/svc/op/script/system/acme.example.com/?script=win2012r2.cmd if errorlevel 1 ( echo not download install cmd win2012r2.cmd goto err ) echo calling %systemroot%\temp\win2012r2.cmd call %systemroot%\temp\win2012r2.cmd >%systemdrive%\logs\win2012r2.log 2>&1 if errorlevel 1 ( echo postprovisioning failed run exit /b 1 ) goto :eof :netconf echo downloading install script win_netcfg.cmd echo curl -sf -o %systemroot%\temp\win_netcfg.cmd http://10.6.7.20/cblr/svc/op/script/system/acme.example.com/?script=win_netcfg.cmd curl -sf -o %systemroot%\temp\win_netcfg.cmd http://10.6.7.20/cblr/svc/op/script/system/acme.example.com/?script=win_netcfg.cmd if errorlevel 1 ( echo not download netcfg cmd win_netcfg.cmd goto err ) echo calling %systemroot%\temp\win_netcfg.cmd call %systemroot%\temp\win_netcfg.cmd >%systemdrive%\logs\netconf.log 2>&1 if errorlevel 1 ( echo networking configuration failed run exit /b 1 ) goto :eof :err echo win_installer.cmd failed run exit /b 1 :end exit /b 0
and end c:\logs\installer.log of:
mounting samba share winlogs l: beginning run stage downloading install script win2012r2.cmd curl -sf -o c:\windows\temp\win2012r2.cmd http://10.6.7.20/cblr/svc/op/script/system/acme.example.com/?script=win2012r2.cmd calling c:\windows\temp\win2012r2.cmd
and c:\logs\win2012r2.log file of:
<all stuff win2012r2.cmd does> run stage completed <-- here end of file should installer.log copying setupact.log copying setuperr.log copying c:\logs\win2012r2.log beginning netconf stage downloading install script win_netcfg.cmd curl -sf -o c:\windows\temp\win_netcfg.cmd http://10.6.7.20/cblr/svc/op/script/system/acme.example.com/?script=win_netcfg.cmd calling c:\windows\temp\win_netcfg.cmd
and c:\logs\netconf.log of:
< stuff netconf > netconf stage completed <-- should installer.log
Comments
Post a Comment