Combine SQL files with command `copy` in a batch file introduce an incorrect syntaxe because it does add an invisible character `U+FEFF`

跟風遠走 提交于 2019-12-13 03:48:34

问题


In a pre-build event, a batch file is executed to combine multiple SQL files into a single one.
It is done using this command :

COPY %@ProjectDir%\Migrations\*.sql %@ProjectDir%ContinuousDeployment\AllFilesMergedTogether.sql

Everything appear to work fine but somehow the result give an incorrect syntaxe error.
After two hours of investigation, it turn out the issue is caused by an invisible character that remain invisible even with notepad++.
Using an online website, the character has been spotted and is U+FEFF has shown in following image.

Here are the two input scripts.
PRINT 'Script1'
PRINT 'Script2'

Here is the output given by the copy command.
PRINT 'Script1' PRINT 'Script2'

Additional info :

  • Batch file is encoded with UTF-8
  • Input files are encoded with UTF-8-BOM
  • Output file is encoded with UTF-8-BOM.
    I'm not sure it is possible to change the encoding output of command copy.
    I've tried and failed.

What should be done to eradicate this extremely frustrating parasitic character?


回答1:


It has turned out that changing encoding of input files to ANSI does fix the issue.
No more pesky character(s).
Also, doing so does change the encoding of the result file to UTF-8 instead of UTF-8-BOM which is great I believe.

Encoding can be changed using Notepad++ as show in following picture.



来源:https://stackoverflow.com/questions/55542197/combine-sql-files-with-command-copy-in-a-batch-file-introduce-an-incorrect-syn

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!