Visual Studio 在批处理文件中插入无效字符 [英] Visual Studio inserts invalid characters in batch files

查看:14
本文介绍了Visual Studio 在批处理文件中插入无效字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些批处理文件,可用于帮助自动化创建和重新加载开发数据库的过程.在 Visual Studio 中(即在 VS 数据库项目中)创建和维护这些批处理文件是有意义的.它们看起来很简单,就像这样:

I've got some batch files that I use to help automate the process of creating and reloading development databases. It makes sense to create and maintain these batch files in Visual Studio (i.e., in a VS Database project). They look pretty simple, like this:

@echo off
echo Setting server and db from defaults.
set SERVERNAME=(LOCAL)
set DB=PLEDGES
echo Creating tables on server %SERVERNAME% and database %DB%
sqlcmd -S %SERVERNAME% -d %DB% -E -i DropAllTables.sql
sqlcmd -S %SERVERNAME% -d %DB% -E -i dbo.UserType.Table.sql
sqlcmd -S %SERVERNAME% -d %DB% -E -i dbo.RegisteredUser.Table.sql
echo Done creating tables.

问题是当我运行它们时,这是输出:

The problem is that when I run them, this is the output:

C:>
'' is not recognized as an internal or external command,
operable program or batch file.
Creating tables on server (LOCAL) and database PLEDGES
Done creating tables.

换句话说,Visual Studio 不知何故以某种方式插入了一组字符,Windows 命令处理器将这些字符解释为命令,即∩╗┐".谷歌搜索对此一无所获.有没有其他人遇到过这个问题?关于修复的想法?

In other words, Visual Studio is somehow invisibly inserting a set of characters that the Windows command processor is interpreting as a command, i.e., "". A Google search returned nothing on this. Has anybody else run into this? Thoughts on a fix?

我有一个解决方法(只需在每个文件的开头添加一个空行,它就会显示错误,但其他方面工作正常),但是每次我运行时,我自己的肛门保留方面都会很恼火这些文件之一.

I've got a workaround (just add a blank line to the beginning of each file, and it'll show the error, but otherwise work fine), but the anal-retentive side of myself gets annoyed each time I run one of these files.

推荐答案

正在发生的事情是 VisualStudio 很聪明,它使您不知道您的批处理文件已保存为非 ASCII 字符编码(例如您的文件是 UTF-8 或其他一些非 ASCII 编码).

What is happening is that VisualStudio is being clever and hiding you from the fact that your batch-file has been saved in a non-ASCII character encoding (e.g. your file is UTF-8 or some other non-ASCII encoding).

我的项目团队因此被抓了几次(如果将文件签入 CVS 会使文件变得一团糟).

My project team has been caught out a few times by this (if the files are checked into CVS it makes the files a mess).

我比较喜欢用Notepad++,看右下角的编码(应该说是ANSI),如果要改就去格式菜单改类型然后保存.

I tend to use Notepad++, look at the encoding on the lower-right (it should say that it is ANSI), if you need to change it go to the format menu and change the type then save.

Visual Studio 应该看起来相同,但文件大小应该减半!

Visual Studio should look identical but the file size should have halved!

这篇关于Visual Studio 在批处理文件中插入无效字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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