0

I keep getting a syntax error complaint and I can't find out why:

cls
set a=.\Data\%Last%.ejl
echo ID: %id% > %a%
echo Last Name: %Last% >> %a%
echo First Name: %First% >> %a%
echo Gender:%Gender% >> %a%
echo Birthday:%Birthday% >> %a%
echo Relation: >> %a%
echo %Relation% >> %a%
1
  • Which line of your script is producing the error? Make sure that echo is on, and then see which line is actually causing the problem. Commented Apr 1, 2014 at 23:30

2 Answers 2

1

This may work for you - if %last% doesn't contain various odd characters.
Some foreign characters are not rendered properly in the default code page.

cls
(
   echo ID: %id%
   echo Last Name: %Last%
   echo First Name: %First%
   echo Gender:%Gender%
   echo Birthday:%Birthday%
   echo Relation:
   echo %Relation%
) >".\Data\%Last%.ejl"
Sign up to request clarification or add additional context in comments.

Comments

1

Wild guess in the absence of information: the variable last contains spaces or some "poison" character (those that are significant to cmd).

Cure: set the target file to "%a%" not %a%. The enclosing quotes ensures batch interprets Space as an ordinary character, not a separator.

To assign a string to a variable, try using set "string=variable text" - the enclosing quotes ensure that any trailing spaces on the line are not included in the value assigned.

Note also that any spaces on either side of the = in a string-set statement will be included - either in the variablename or the string assigned.

Note also that your design appears to have a problem - what happens where there is more than one "lastname" in your list - John Doe and Jane Doe?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.