windows BAT文件中的“输入行太长”错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16821784/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 10:33:45  来源:igfitidea点击:

"Input line is too long" error in BAT File

windowsbatch-file

提问by Carlos Grossi

I am having a problem executing a bat file. After some time running I get the "input line is too long" error.

我在执行 bat 文件时遇到问题。运行一段时间后,我收到“输入行太长”错误。

The structure of the bat file is simple. There is a main bat file that calls 10 other bat files that are responsible for updating data of my system modules. In the updating data bat files there are lot of calls for a command(.cmd file) of my system that is responsible for updating the data through some calculations.

bat文件的结构很简单。有一个主要的 bat 文件调用 10 个其他 bat 文件,这些文件负责更新我的系统模块的数据。在更新数据 bat 文件中,有很多对我系统的命令(.cmd 文件)的调用,该命令负责通过一些计算更新数据。

The point is, when the process was running in a Windows 2003 Server it was ok. No errors.

关键是,当进程在 Windows 2003 Server 中运行时,它没问题。没有错误。

Then, when it was upgraded to Windows 2008 Server, I execute the main bat file, several hours later I got the "Input line is too long" error. I can't even execute any command included in the updated data bats manually in that cmd window. But if I close the cmd window and open a new one I can execute the commands without errors.

然后,当它升级到 Windows 2008 Server 时,我执行主 bat 文件,几个小时后我收到“输入行太长”错误。我什至无法在该 cmd 窗口中手动执行更新数据蝙蝠中包含的任何命令。但是如果我关闭 cmd 窗口并打开一个新窗口,我可以毫无错误地执行命令。

Anybody had the same problem? Or a solution?

有人遇到过同样的问题吗?还是解决办法?

Thanks in advance.

提前致谢。

回答by Cookie Butter

I have had this same problem when executing a build script in a cmd window. After about 13 times I got that same error. The build script had to make sure that vcvarsall.bat was run so it executed vcvarsall.bat every time.

在 cmd 窗口中执行构建脚本时,我遇到了同样的问题。大约 13 次后,我得到了同样的错误。构建脚本必须确保 vcvarsall.bat 已运行,因此它每次都执行 vcvarsall.bat。

vcvarsall.bat is not smart enough to only add things to the pathif they are not already there so a bunch of duplicate entries were added.

vcvarsall.bat 不够聪明,只能在path它们不存在的情况下向其中添加内容,因此添加了一堆重复的条目。

My solution was to add an if defined check on an environment variable which I know is set by vcvarsall.bat...

我的解决方案是在我知道由 vcvarsall.bat 设置的环境变量上添加 if 定义检查...

if not defined DevEnvDir (
    call vcvarsall.bat
)

Check your path environment variable after each run and see if it is growing. If it is and there are duplicates, you will need to be smart about adding stuff to the path. There are several ways to be smart about it.

每次运行后检查您的路径环境变量,看看它是否在增长。如果是并且存在重复项,则您需要聪明地将内容添加到path. 有几种方法可以让它变得聪明。

回答by Jim Bethancourt

I happened upon this error just now for the first time after running the same set of commands (stop / start an application server) a number of times.

在多次运行相同的命令集(停止/启动应用程序服务器)后,我刚刚第一次遇到此错误。

The error stopped when I opened up a new command line and tried the commands from the new command line console.

当我打开一个新命令行并尝试来自新命令行控制台的命令时,错误停止了。

回答by Chris

I realize this is pretty old, but the other issue I ran into was having a "at the end of the command I was calling. I was attempting to call:

我意识到这已经很老了,但我遇到的另一个问题是"在我调用的命令末尾有一个。我试图打电话:

"C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\..\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe""

If you notice, I have two "at the end of the line. This was causing my issues (Notepad++ included it when I typed the quotes). Removed that, all good. Again, may not be your issue, but if anyone else comes seeking info and nothing else works, check this. :)

如果你注意到,我"在行尾有两个。这导致了我的问题(Notepad++ 在我输入引号时包含了它)。删除了,一切都很好。同样,可能不是您的问题,但如果其他人来寻求信息而没有其他任何工作,请检查此内容。:)

回答by James Holderness

There is a Windows knowledge base articleon this subject. They don't mention Windows 2008 server, but they did mention the difference in size between other versions of the OS, so it wouldn't be surprising is there was a difference between 2003 and 2008.

一篇关于此主题的Windows 知识库文章。他们没有提到 Windows 2008 服务器,但他们确实提到了其他版本的操作系统之间的大小差异,因此 2003 年和 2008 年之间存在差异也就不足为奇了。

As for solutions to the problem, some of their suggestions include:

至于问题的解决方案,他们的一些建议包括:

  • Modify programs that require long command lines so that they use a file that contains the parameter information, and then include the name of the file in the command line.
  • Use shorter names for folders and files.
  • Reduce the depth of folder trees.
  • 修改需要长命令行的程序,使其使用包含参数信息的文件,然后在命令行中包含文件名。
  • 为文件夹和文件使用较短的名称。
  • 减少文件夹树的深度。

You can read the whole article if you want to see what else they have to say, but those were the suggestions that looked most likely to apply to you.

如果你想看看他们还有什么要说的,你可以阅读整篇文章,但这些是最有可能适用于你的建议。

回答by ixe013

It can also happen if the spaces in your file (ansi character 0x20) are really non-breaking spaces (I had 0xA0, but yours may vary). This can happen if you copy/pasted from the internet to a UTF-8 aware editor.

如果您的文件中的空格(ansi 字符0x20)确实是不间断空格(我有0xA0,但您的可能会有所不同),也会发生这种情况。如果您从 Internet 复制/粘贴到 UTF-8 识别编辑器,则可能会发生这种情况。

The result depends on the current codepage of windows, your editor and such. To fix:

结果取决于 Windows 的当前代码页、您的编辑器等。修理:

  1. Use an hexadecimal editor
  2. Look at how spaces are represented
  3. Search and replace your representation
  1. 使用十六进制编辑器
  2. 看看空间是如何表示的
  3. 搜索并替换您的表示

I used HxDto search and replace 0xA0to 0x20.

我使用HxD搜索并替换0xA00x20.

回答by sg_man

I ran into this also.

我也遇到了这个。

I was trying to run vcvars.bat as others here seem to be trying.

我试图运行 vcvars.bat,因为这里的其他人似乎正在尝试。

The underlying problem for me seemed to be that my PATH variable was polluted with repeats of an already pretty lengthy path. Fixing up my path seemed to fix the issue for me (in a new terminal, of course). Note that this fix isn't specific to vcvars.bat or anything Visual Studio related.

对我来说,潜在的问题似乎是我的 PATH 变量被一条已经很长的路径的重复污染了。修复我的路径似乎为我解决了这个问题(当然,在一个新的终端中)。请注意,此修复程序并非特定于 vcvars.bat 或任何与 Visual Studio 相关的内容。

I'm curious if Cookie Butter's solution is a workaround and the underlying problem is the same.

我很好奇 Cookie Butter 的解决方案是否是一种解决方法并且潜在的问题是相同的。

回答by Hossam Houssein

using CALL several times to run another batch that sets env will increment the value of the var you are setting,hence the error at some point

多次使用 CALL 运行另一个设置 env 的批处理将增加您正在设置的 var 的值,因此在某些时候会出现错误

call set path=some\path;%path%

调用 set path=some\path;%path%

running the above command in cmd for many times will produce the error

在cmd中多次运行上述命令会产生错误