How can I test for errors in a .bat file that calls an .exe? - windows

I'm writing a .bat file that calls a .exe that processes a bunch of documents. I am writing it to test the .exe's performance. Currently, the .bat file runs a for loop to run the .exe on every file in the folder. Sometimes the .exe will run into errors and will not be able to finish running due to incompatibility between the document and the .exe (still working on perfecting the .exe). How can I tell my .bat file to mark the bad files as errors and continue processing the rest of the files?
Edit: I don't want to terminate the batch file; I'd like to terminate the .exe for that specific file, and then continue with the for loop.

Related

running batch files inside another batch file

I have made a batch script to run some .exe files and .bat files. The format of the script is as follows:
a.exe
b.exe
c.bat
d.bat
e.bat
f.exe
g.exe
but the problem is when I run the script it is only executed till c.bat. d.bat is not executing. Is there any problem in writing the batch script for executing other batch files?
just in case you missed the full application of call
a.exe
b.exe
call c.bat
call d.bat
call e.bat
f.exe
g.exe
is how your script should now look.
if you use the 'call' command, the batch files next batch/exe file wouldn't execute unless the batch file stops. Instead, use the 'start' command. that way, it'll execute the batch in a new window

VBS Runs from Explorer but not Task Scheduler

I have a legacy VBS script that runs on a schedule via task scheduler. The script checks a folder (located in a mapped network drive) and processes the files it finds in the folder.
Recently it just stopped working. I didn't write this script, I've only inherited it. It no longer seems to find files in the folder it's looking in, even when they're there. To test we created a log file and wrote file names to it. When manually double-clicking the file and running it from explorer it writes to the log file and sees everything in the directory. If you run it from the Task Scheduler it sees no files and writes nothing to the log file. It also runs for days and never seems to exit when the scheduler runs it, even if there are no files and when I run manually it closes immediately when there are no files.
We have several other legacy scripts that are very similar in function to this one and they all work exactly as expected without issue.
This script is run as administrator (the others are as well). I set the "Start In" to it's current directory (the start in directive is not set for the other scripts and they function normally) and this did not help.
This script uses full file paths to everything (the others do as well).
It works as expected only when double clicked.

7zip sfx is executing RunProgram before it extracts all the files

I have a 7 zip self extracting exe, it is archived as shown below:
[mainfolder]
start.exe (a C++ bootstrapper)
[subfolder] (contains all my applications assemblies and executable
Now my config.txt is running the start.exe (through "RunProgram") which will actually run a executable in [subfolder]. Now this is failing as the extraction all the files in [subfolder] is still not complete (i did find all files in extraction location) by the time "start.exe" is started.
One other strange thing is the extraction of all files in [subfolder] is completed if at all i specify to run a exe inside subfolder in config file i.e to "RunProgram", or even i specify a random text to "RunProgram" at least the extraction is complete.
What it could be that if prefer to run a file in [mainfolder] causes the [subfolder] to be extracted incompletely? Please help.
It was a wrong analysis, the problem was not with extraction.. all the time it was extracting properly. But when i was trying to call bootstrapper it used to call another exe and exit so SFX thought the process has finished executing and was deleting files.
So when there is chain of calls from diff application care should be taken that at least the application you start from (through "RunProgram","ExecuteFile" or from any thing..) stays alive till all needy application exits.
One workaround is to nest the sfx. You first make an sfx that include all the necessary files, and then nest it together with your bootstrapper and a script to extract that and run your bootstrapper inside another sfx which will run that script.
See more: SFX with 7-zip : Is it possible to run a included .bat file before extracting the files?

Self executing delete files

How would I create a self executing batch file to delete files in a specific folder.
Scenario: I have a folder on a server where all the scannered documents go to once they have been scanned. They want a the scanned documents to be deleted after 1 day. Can a batch file be created to do that everyday?
You can use the built in task scheduler - this can call a batch file, or just about anything.
(I am assuming Windows, since you mention batch files).
This is quite a well known method, and was documented in MSDN some time ago. This technique works on both Windows 95 and Windows NT. It works because MS-DOS batch files are able to delete themselves. To test this technique, create a small batch file containing the single command:
del %0.bat
The batch file, when run, deletes itself and issues an error "The batch file cannot be found". This error is just a simple message, so it can be safely ignored. By itself this isn't too useful, but when modified to delete our executable it solves our problem, albeit in a rather forceful manner. Our executable will create a batch file (called C:\DelUs.bat) with the following content:
:Repeat
del "C:\MYDIR\MYPROG.EXE"
if exist "MYPROG.EXE" goto Repeat
rmdir "C:\MYDIR"
del "\DelUS.bat"
This batch file repeatedly attempts to delete the specified file, and will run continuously consuming CPU until it succeeds. When the execuable has been deleted, the batch file then deletes itself.
The executable needs to spawn off the batch file using CreateProcess, and then should exit immediately. It would be a good idea to give the batch file's thread of execution a low priority so that it doesn't get much execution time until the original executable has terminated.
Read the entire article at http://www.catch22.net/tuts/self-deleting-executables that contains the full code to this technique.

Batch File calls VBScript which calls EXE that won't open

I have a VBS file 'migration.vbs' that runs a number of commands and then calls an AutoIt .exe file to begin the uninstall of a product. The entire script runs successfully when you call it by itself from the command line with 'cscript migration.vbs'
This script is going to be pushed out to a number of other machines where techs need to be able to double-click to run it. A lot of the machines don't execute VBS by default on a double click, so I've added a batch file to run it.
The problem is that when the batch file calls the VBS, it starts to run but never calls the exe. It just.. skips that step. I'm guessing there's an issue with nested system calls or something that I don't know about.
Anyways, any solutions? I'd rather not put the EXE call in the batch file due to logic checking the VBS does against registry keys (that'd be hard/impossible to duplicate in BAT).
Thanks again
start.bat
START /WAIT cscript .\data\migration.vbs
migration.vbs
WSHSHell.Run "uninstall.exe", 0, True
There is no nested system calls limit, I'm guessing that the path or current directory is wrong, try using a full path or monitor the filesystem calls with Process Monitor

Resources