Parentheses cause error

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
miskox
Posts: 656
Joined: 28 Jun 2010 03:46

Parentheses cause error

#1 Post by miskox » 23 Dec 2014 13:02

Hi all!

I have this code:

a.cmd

Code: Select all

@echo off
set recstring=SOME TEXT with ( and ). Errors.&rem
goto %1

:1
echo 1
>outfile1.txt (echo %recstring%)
goto :EOF

:2
echo 2
echo %recstring%>outfile2.txt
goto :EOF

:3
echo 3
(
   filepointer.exe 1 0
   echo %recstring%
)>outfile3.txt
echo END


If I run it:

Code: Select all

c:\temporary\dostips>a.cmd 1
1
. was unexpected at this time.

c:\>a.cmd 2
2

c:\>a.cmd 3
3
. was unexpected at this time.

c:\>


FILEPOINTER.EXE is Aacini's excelent program (see viewtopic.php?p=34051#p34051).

The example above will work without this program because of the error so you don't have to have it.

Any ideas how to avoid this error when parentheses are present in a record?

I want step 3 to work (with filepointer.exe).

Thanks.
Saso

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Parentheses cause error

#2 Post by Squashman » 23 Dec 2014 13:16

Not sure if this is what you are trying to do or not.

Code: Select all

@echo off
set "recstring=SOME TEXT with ( and ). Errors. &rem"
goto %1

:1
pause
echo 1
>outfile1.txt echo %recstring%
pause
goto :EOF

:2
echo 2
echo %recstring%>outfile2.txt
goto :EOF

:3
echo 3
(
   filepointer.exe 1 0
   echo %recstring%
)>outfile3.txt
echo END

Yury
Posts: 115
Joined: 28 Dec 2013 07:54

Re: Parentheses cause error

#3 Post by Yury » 23 Dec 2014 14:11

Code: Select all

@echo off
set "recstring=SOME TEXT with ( and ). Errors."
goto %1

:1
echo 1
>outfile1.txt (cmd /v:on /c echo !recstring!)
goto :EOF

:2
echo 2
cmd /v:on /c echo !recstring!>outfile2.txt
goto :EOF

:3
echo 3
(
   filepointer.exe 1 0
   cmd /v:on /c echo !recstring!
)>outfile3.txt
echo END

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Parentheses cause error

#4 Post by penpen » 23 Dec 2014 14:17

I think you should escape the brackets, if you want to output them:
set "recstring=SOME TEXT with ^( and ^). Errors."
(echo(%recstring%)
:: versus
set "recstring=SOME TEXT with ( and ). Errors."
(echo(%recstring%)
Reason the first ')' character ends a block, so the '.' character is treated as an instruction.

penpen

Aacini
Expert
Posts: 1927
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Parentheses cause error

#5 Post by Aacini » 23 Dec 2014 17:59

Use this (I just tested it):

Code: Select all

:3
echo 3
(
   filepointer.exe 1 0
   for /F "delims=" %%a in ("%recstring%") do echo %%a
)>outfile3.txt
echo END

Antonio

miskox
Posts: 656
Joined: 28 Jun 2010 03:46

Re: Parentheses cause error

#6 Post by miskox » 24 Dec 2014 03:20

Aacini wrote:Use this (I just tested it):

Code: Select all

:3
echo 3
(
   filepointer.exe 1 0
   for /F "delims=" %%a in ("%recstring%") do echo %%a
)>outfile3.txt
echo END

Antonio


First test shows that it is working. I have to test this with some real data and in the middle of a file.

Thanks again Antonio. I recevied many great ideas/solutions from you recently.

Saso

Post Reply