2

I am having an issue with setting a variable from a text file in a batch script. There is only one line in the text file and it is testabc.

The script is

set /p p_password=<c:\temp\passport.txt
echo %p_password%

The echo statement should have testabc, but it is actually having the below ■t.

I even tried it with a for loop

for /f "delims=" %%a in (c:\temp\passport.txt) do set p_password=%%a
echo %p_password%

I still get the same output; ■t

Any help is much appreciated.

1
  • 1
    Is it possible the text file is saved as UTF-8 with a BOM? Commented Jun 14, 2017 at 21:35

1 Answer 1

1

Yes, I can confirm that using different a file encoding format will fix this problem.

Using the input text file mentioned in your question, and saving the text file using UltraEdit, the results are listed below for the different encoding formats:

  • ANSI/ASCII = testabc
  • UTF-8 = ∩╗┐testabc
  • UTF-16 =  ■t
  • UTF-8 - NO BOM = testabc
  • UTF-16 - NO BOM = t
  • UTF-16 - Big Endian = ■ 
  • UTF-16 - Big Endian - NO BOM = (empty string)
  • Unicode - ASCII Escaped = testabc

As mentioned earlier by the commentor, it seems your text file was saved with a Byte order mark.

Sign up to request clarification or add additional context in comments.

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.