简体   繁体   中英

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).

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.

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):

 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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM