Interesting. Based on what gets output without the @echo off
, it appears to be a difference between when the variables get evaluated (as part of the "outer" shell or the "inner" one, I suspect).
However, if you pass the parameters to a function as follows, it appears to work okay in both XP and Win7:
@echo off
goto :main
:xyzzy
if "x%1"=="x""" goto :eof
echo %1
echo %2
echo.
goto :eof
:main
echo.&echo.
ping -n 1 google.com
echo.&echo.
for /f "tokens=1*" %%a in ('ping -n 1 google.com') do call :xyzzy "%%a" "%%b"
echo.&echo.
You'll notice I've also ditched blank lines in the xyzzy
function since they seem to add no value. If you really want them output, just remove the first line of that function. The output of that script has the first character preserved, unlike the original script:
Pinging google.com [74.125.225.105] with 32 bytes of data:
Reply from 74.125.225.105: bytes=32 time=253ms TTL=43
Ping statistics for 74.125.225.105:
Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 253ms, Maximum = 253ms, Average = 253ms
"Pinging"
"google.com [74.125.225.105] with 32 bytes of data:"
"Reply"
"from 74.125.225.105: bytes=32 time=267ms TTL=43"
"Ping"
"statistics for 74.125.225.105:"
"Packets:"
"Sent = 1, Received = 1, Lost = 0 (0 loss),"
"Approximate"
"round trip times in milli-seconds:"
"Minimum"
"= 267ms, Maximum = 267ms, Average = 267ms"