Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
miskox
- Posts: 630
- Joined: 28 Jun 2010 03:46
#1
Post
by miskox » 22 Nov 2016 05:56
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
-
jeb
- Expert
- Posts: 1055
- Joined: 30 Aug 2007 08:05
- Location: Germany, Bochum
#2
Post
by jeb » 22 Nov 2016 06:02
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.
-
dbenham
- Expert
- Posts: 2461
- Joined: 12 Feb 2011 21:02
- Location: United States (east coast)
#3
Post
by dbenham » 22 Nov 2016 07:29
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
-
miskox
- Posts: 630
- Joined: 28 Jun 2010 03:46
#4
Post
by miskox » 22 Nov 2016 07:50
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
-
dbenham
- Expert
- Posts: 2461
- Joined: 12 Feb 2011 21:02
- Location: United States (east coast)
#5
Post
by dbenham » 22 Nov 2016 08:57
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
-
miskox
- Posts: 630
- Joined: 28 Jun 2010 03:46
#6
Post
by miskox » 22 Nov 2016 13:54
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