Page 1 of 1
Different behaviour of a command on XP and WIN10
Posted: 22 Nov 2016 05:56
by miskox
Hello all!
Code: Select all
@echo off
set cmmnt= &rem ONE SPACE
<nul set /p "=%cmmnt%" >temporary.cmmnt
for %%q in (temporary.cmmnt) do (set /a strlen=%%~zq)
echo strlen=%strlen%_
Executing this on XP gives result 1, executing this on WIN10 gives rezult 0. Any ideas why?
Changing the code to:
Code: Select all
@echo off
set cmmnt= &rem ONE SPACE
echo(%cmmnt%>temporary.cmmnt
for %%q in (temporary.cmmnt) do (set /a strlen=%%~zq)
set /a strlen-=2
echo strlen=%strlen%_
Gives correct result 1.
Saso
Re: Different behaviour of a command on XP and WIN10
Posted: 22 Nov 2016 06:02
by jeb
Hi miskox,
the difference is in the set /p behaviour.
This is changed from XP to Vista.
From Vista leading white space characters are removed from the output.
That's the cause, W10 removes the space and writes an empty file.
Re: Different behaviour of a command on XP and WIN10
Posted: 22 Nov 2016 07:29
by dbenham
I tried to document the output behavior of SET /P under XP vs later versions at
viewtopic.php?f=3&t=4209.
Presumably Win 10 behaves the same as Vista and Win 7
Dave Benham
Re: Different behaviour of a command on XP and WIN10
Posted: 22 Nov 2016 07:50
by miskox
What can I do?
I see that commands:
and
are causing me problems if cmmnt contains ( or ).
I will see if this
viewtopic.php?f=3&t=4213 helps me.
Thanks.
Saso
Re: Different behaviour of a command on XP and WIN10
Posted: 22 Nov 2016 08:57
by dbenham
The standard answer whenever trying to work with "problem" characters - Use delayed expansion.
Works in all situations except when expanding FOR loop variable that may contain !
Code: Select all
setlocal enableDelayedExpansion
>temporary.cmmnt echo(!cmmnt!
endlocal
Dave Benham
Re: Different behaviour of a command on XP and WIN10
Posted: 22 Nov 2016 13:54
by miskox
dbenham wrote:The standard answer whenever trying to work with "problem" characters - Use delayed expansion.
Works in all situations except when expanding FOR loop variable that may contain !
Code: Select all
setlocal enableDelayedExpansion
>temporary.cmmnt echo(!cmmnt!
endlocal
Dave Benham
Thank you.
Problem solved.
Saso