Page 1 of 1

Parentheses cause error

Posted: 23 Dec 2014 13:02
by miskox
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

Re: Parentheses cause error

Posted: 23 Dec 2014 13:16
by Squashman
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

Re: Parentheses cause error

Posted: 23 Dec 2014 14:11
by Yury

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

Re: Parentheses cause error

Posted: 23 Dec 2014 14:17
by penpen
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

Re: Parentheses cause error

Posted: 23 Dec 2014 17:59
by Aacini
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

Re: Parentheses cause error

Posted: 24 Dec 2014 03:20
by miskox
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