在批处理文件中将SQL文件与命令"copy"结合使用会引入不正确的语法,因为它确实添加了不可见的字符"U + FEFF" [英] Combine SQL files with command `copy` in a batch file introduce an incorrect syntaxe because it does add an invisible character `U+FEFF`

查看:394
本文介绍了在批处理文件中将SQL文件与命令"copy"结合使用会引入不正确的语法,因为它确实添加了不可见的字符"U + FEFF"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在预构建事件中,将执行批处理文件以将多个SQL文件组合为一个文件.
使用以下命令即可完成:

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

一切似乎都可以正常运行,但是结果以某种方式给出了不正确的语法错误.
经过两个小时的调查,结果发现问题是由即使使用记事本++仍然不可见的不可见字符引起的.
在一个在线网站上,该字符已被发现,并且在下图中显示了U+FEFF.

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.

这是两个输入脚本.
PRINT 'Script1'
PRINT 'Script2'

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

这是复制命令给出的输出.
PRINT 'Script1' PRINT 'Script2'

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

其他信息:

  • 批处理文件使用UTF-8编码
  • 输入文件使用UTF-8-BOM编码
  • 输出文件使用UTF-8-BOM编码.
    我不确定是否可以更改命令copy的编码输出.
    我尝试过并失败了.
  • 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.

该如何消除这种令人沮丧的寄生字符?

推荐答案

事实证明,将输入文件的编码更改为ANSI确实可以解决此问题.
不再有讨厌的角色.
此外,这样做确实会将结果文件的编码更改为UTF-8而不是UTF-8-BOM,我相信这很好.

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.

可以使用Notepad ++更改编码,如下图所示.

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

这篇关于在批处理文件中将SQL文件与命令"copy"结合使用会引入不正确的语法,因为它确实添加了不可见的字符"U + FEFF"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆