[英]Windows batch script stops working after a few iterations
I have a windows batch script that just calls vcavars32 for a C compiler, deduces the name of my C program based on the working directory name, saves some content from the user from the command-line, then compiles and runs my program from the commandline (if you know what USACO is, I was hoping this script would help me quickly automate testing). 我有一个Windows批处理脚本,该脚本只为C编译器调用vcavars32,根据工作目录名称推断我的C程序的名称,从命令行保存用户的某些内容,然后从命令行编译并运行我的程序(如果您知道USACO是什么,我希望该脚本可以帮助我快速进行自动化测试)。
The script works fine for a while, but after I call it a few times it starts complaining 该脚本可以正常工作一会儿,但是在我几次调用后,它开始抱怨
The input line is too long.
The syntax of the command is incorrect.
And it will stop working, until I close cmd and then reopen a new cmd window. 它将停止工作,直到我关闭cmd,然后重新打开一个新的cmd窗口。
My batch script right now pretty much looks like this right now (I also have a ton of comments and a few gotos in my actual script to make it a little more convenient, eg don't run more > %myFolder%.in
if %myFolder%.in
already exists): 现在,我的批处理脚本现在看起来几乎是这样的(我在实际脚本中也有大量注释和一些注释,以使其更加方便,例如,不要运行
more > %myFolder%.in
如果%myFolder%.in
已经存在):
call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\vcvars32.bat"
for %%A in (".") do set "myFolder=%%~nxA"
more > %myFolder%.in
CL %myFolder%.c /nologo && %myFolder%.exe >nul && type %myFolder%.out
del /q %myFolder%.exe %myFolder%.obj %myFolder%.out
Can I get my script to work every time? 我能否每次都运行脚本? Why am I getting this error?
为什么会出现此错误?
Turns out jeb
's comment was right on. 原来
jeb
的评论是对的。
It looks like vcvars.bat
was adding to path
every time it was run, and after a few times, I guess it got too long. 好像
vcvars.bat
每次运行时都添加到path
,并且经过几次,我猜它太长了。
I modified the script to only run vcvars.bat
if it hasn't been run yet, and now I don't get that problem anymore. 我将脚本修改为仅在尚未运行
vcvars.bat
情况下运行,现在我不再遇到该问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.