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, e.g. 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.
Related
I use ebook-convert.exe from a batch file, and on one of my machines (old Windows vista laptop), any calls ebook-convert.exe prevent further commands in a batch file from running (in that .bat file, or in that cmd shell instance for instance). The conversion to .mobi actually succeeds, prints no errors even in -v -v full verbose mode. I tried versions 1.20.0 and 0.9.6 of calibre portable. It seems to be related to the executable itself, and not to the specific conversion job (just running it with -h flag has same effect). I tried running cmd in administrator mode, wrapping it with 'call' command, nothing helps. Assuming the calibre issue is a black hole that can't be solved, is there a DOS trick I could possibly try to keep batch commands running no matter what odd thing happens with ebook-convert.exe on that machine?
Using call in a batch file should work on normal console programs but it is possible for programs to "escape" if they really want to.
Using Start instead might work but it does not wait by default and its syntax is not sane:
Start /B /WAIT c:\path\without\spaces.exe optionalParameter
or
Start "" /B /WAIT "c:\path\w i t h\spaces.exe" optionalParameter
Remove /B to run the application in a new console.
Another option is to call ping localhost and For (to get the file size with %%~zA) in a loop until the size of the destination file stops increasing. This is a bit of a hack and might not work, it depends on how the converter opens the file and how often it flushes the writes.
Okay this is my ToolChain setup:
I got a bat script that is calling a further bat script
The second bat script is calling an .exe which is performing autoit's on a software like starting, saving and closing.
In other words: bat > bat > exe (AutoIt) > exe (a Parser)
Okay here is the issue, the software (Parser) that will be started at least is some kind of weird, it won't find important files, if it's not being started from the same directory.
So as example if i put my autoit .exe or my .bat file into the directory of the software and start it - all is fine. But if i move my exe or my bat scripts outside of the directory and call it, it won't find files to start working.
For exactly this reason i made a second bat file and tried to set the path (set PATH=%PATH%;D:/filetype/dbcparser/) but that didn't have any effect on my case; if i call every bat or exe file not from the directory, it won't work correctly.
I hope someone found something like this before and could give me a hint for a workaround.
I was in the same situation, but using cd before start worked for me(whole file):
#echo off
cd "<start here>"
start "" call "<start here>your.bat"
also if you have PATH problems, try even this:
#echo off
cd "<start here>"
set PATH=<something>;%PATH%
start "" call "<start here>your.bat"
For my work I have to run a string in "run".
I want to make this in a bat file but the arguments are not used but without them the program will not run.
This is the string:
"C:\Program files (x86)\MicroTouch\MT7\TwUI.exe" TwUICP.dll CPMain
Can someone help me with this problem?
You can simply put the same line of code into your bat file:
"C:\Program files (x86)\MicroTouch\MT7\TwUI.exe" TwUICP.dll CPMain
There are some options you can use. For example if you want the program to run hidden in background you can add start /b before the line. start /w will make the cmd window stay open and wait for your program to finish. You can even definde which CPU cores the program should use. For more information open the console and type start /? or check out http://ss64.com/nt/start.html.
Have the same problem, same software i think...
"C:\Program Files (x86)\MicroTouch\MT 7\TwUI.exe" twuicp.dll CPMain
Running that line through task manager -> new task will open a tool to configure touch-screen options, calibrate, etc...
Well same line doesnt work in a bat or cmd file. If i try to launch this tool through cmd.exe it doesnt work either.
The answer is always the same:
USAGE: twui <DLL name> <UI symbol name>
This works, but same line in cmd.exe dont
So I tried and tried but couldn't figure out this one for some reason.
how can I run a task from a desired directory instead of System32 directory where cmd.exe is.
so, when I schedule a task and try to run it ..
command prompt suppose to go to "c:\users\aaa\bbb\ccc" and then pass the argument.
Instead, It's starts at c:\Windows\System32 and fails.
Could anybody help me with this please?
I really appreciate it.
Thank you.
EDIT --
so, now I have a run.bat file with following content in it ...
C:\Users\aaa\bbb\ccc\dd (location to my testrunner.bat file)
testrunner.bat Scripts/all.suite website-address ie (command for the task I wanna perform)
net stop schedule (since window is poping up and going away way to fast, I added this to stop it (not working))
type run.bat
#echo off
cd C:\Users\aaa\bbb\ccc\dd
rem this will show all files in dir
rem is the file you're expecting listed?
dir
rem notice how you can make comments with a leading rem(ark)
#echo starting scripts\all.suite
rem you have to change this to have the full path using Windows X:\dir\dir conventions
c:\home\Scripts\all.suite website-address
#echo done running scripts\all.suite website-address
#echo shutting down
net stop schedule
So its still not clear exactly to me your goal. The reason I added the cd c:\... command is that will **C**hange **D**irectory to the path specified.
This is what you need so you can "run a task from a desired directory instead of System32".
Copy everything from the first #echo off to the last net stop and using notepad, paste it into a file, fix command names and paths website-urls, etc, then save that file to c:\temp\testrunner.bat.
Open a cmd.exe window and test that the script works. Just paste c:\temp\testrunner.bat on to cmd-line and hit enter. If that works, then made an entry in the scheduler to run c:\temp\testrunner.bat . I don't know the specifics of running a script for scheduler, so look for clues on the input screen. Is the an option to run 'now'?
If the .bat file doesn't work from the command-line, then you have to fix the file before you try running it in the scheduler. As your command Scripts/all.suite website-address is a little vague, you'll do better to post a new question asking for help to fix the .bat file and use a sample command that people will be able to use on their PCs at home.
IHTH.
Following are the contents of the file "vs.bat"
call "C:\Program Files (x86)\Microsoft Visual Studio 8\Common7\Tools\vsvars32.bat"
call path.bat
dea usev bis
cd ana
call b-env-i.bat
When I execute this batch file, execution stops after the following step.
dea usev bis
Can anyone please help in pointing out what went wrong here and how I can get all the commands to execute. Note that the aforementioned command (dea usev bis) works fine (both in the batch and if executed separately). dea is the name of the executable and "usv bis" are runtime parameters to the "dea" exe.
I'm running Windows 7.
Clarification:
When I run vs.bat, after the third call "dea usev bis" has executed successfully, the batch file stops executing further. That is both the following calls (which are part of VS.bat) don't get executed
cd ana
call b-env-i.bat
Note that the call "dea usev bis" takes around 20 secs to execute, both when run individually and when run as part of the script.
Update:
I've tried paxdiablo's suggestions, with the following results:
[C:\dea]for %i in (dea.cmd) do #echo %~$PATH:i
ECHO is on.
[C:\dea]for %i in (dea.bat) do #echo %~$PATH:i
ECHO is on.
[C:\dea]for %i in (dea.exe) do #echo %~$PATH:i
C:\dea\bin\dea.exe
[C:\dea]where dea.exe
C:\dea\bin\dea.exe
C:\dea\bin\dea.exe.1
C:\dea\bin\dea.exe.ia64
When I run it explicitly via the following, I still encounter the same issue
c:\dea\bin\dea.exe usev bis
And, as I said earlier, changing the script to call dea does not fix the issue either.
Is there anything else that I can try?
It looks like you're trying to call another batch/script file which, if you leave off call, will simply be chained to rather than called (chained to, in this context, means it doesn't return). I'd suggest changing that line to:
call dea usev bis
By way of example, consider the scripts go2.cmd:
#echo off
echo %1
and go.cmd:
#echo off
call go2 1
go2 2
echo 3
Executing go will only give you:
1
2
because the go2 2 line chains to, rather than calls that script. The call go2 1 line, however, works fine.
And, even if you have a dea.exe file, that does not necessarily mean it's the one being run. Your script calls dea so leaves the choice as to what actually gets run to the shell (searching the path, trying different extensions and so on).
To check whether or not the thing you're actually calling is a batch file or not, you can do the following. First, execute the following commends:
echo %PATH%
for %i in (dea.cmd) do #echo %~$PATH:i
for %i in (dea.bat) do #echo %~$PATH:i
for %i in (dea.exe) do #echo %~$PATH:i
(or I think you can just use where dea* if you're running Win 7+, see here for details).
This will show you if there is a dea.cmd/bat/exe in your path, and tell you where in the path the relevant directories are. If there is a script version, it may exist in the path before the exe version. You can simply examine your %PATH% environment variable to figure out which directory comes first.
Second, if you have the exe in c:\dea\bin, try running that explicitly from your script with:
c:\dea\bin\dea.exe usev bis
If that returns okay, it adds support to the fact a script version is being used instead.
Thirdly, you could just change the script as suggested (add call) and see if that fixes it. If it is referencing a script, that will fix it.
If none of those work (and this appears to be the case based on your response that dea is definitely an exe file), you need to start looking into exactly where the failure occurs. This can be done by placing an echo statement in between every single line so that you can see what's causing the issue. In other words, something like:
echo DEBUG a & time <nul:
call "C:\Program Files (x86)\Microsoft Visual Studio 8\Common7\Tools\vsvars32.bat"
echo DEBUG b & time <nul:
call path.bat
echo DEBUG c & time <nul:
dea usev bis
echo DEBUG d & time <nul:
cd ana
echo DEBUG e & time <nul:
call b-env-i.bat
echo DEBUG f & time <nul:
That will both give you timings for the things that do work and hopefully make it obvious what's not working.