Combine SQL files with command `copy` in a batch f

2019-08-16 15:22发布

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.
enter image description here

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条回答
我欲成王,谁敢阻挡
2楼-- · 2019-08-16 15:56

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. enter image description here

查看更多
登录 后发表回答