After Blat executes, you can check errorlevel for problems with Blat.
for %%f in (C:\Bartender\Printfiles\*.txt) do call :procFile %1 %%f
C:\POS\Blat\blat.exe %2 -tf C:\POS\Blat\recipients.txt -cf C:\POS\blat\ccrecipients.txt -bf C:\POS\Blat\bccrecipients.txt -subject "Your Sales Results from %1" -sig C:\POS\blat\sig.txt -debug -log C:\POS\Blat\log.txt
if errorlevel 1 goto :eof
MOVE %2 C:\Bartender\PrintFiles\Archive\
In this example shown above, an error level value of zero will execute the MOVE command; zero indicates success. Any value other than zero will be an error and go directly to the label :eof that follows the MOVE command. All values returned from Blat will be positive, with zero being the lowest value.
The other thing about the example above is that it takes care of multiple files. Windows batch files can call internal labels as if calling an external program. The example above does that, it calls the internal label :procFile for each file found in your Printfiles folder that has .txt extension. The first argument given to the internal label is still the RUNDATE you mentioned, but the second argument passed to this internal label is the filename found in Printfiles folder.
Sent: Sunday, June 04, 2017 11:32 PM
Subject: Re: [blat] Can Blat be used when name of the attached file is unknown?
Thanks. That was helpful.
But it seems I need to do some more to cover all cases, especially Errors.
First, let me explain a bit:
The POS Program stores a .txt File with the results in a specified Folder. The name of this file is printfile20170604.txt, where 20170604 does not refer to the date of file creating, but rather to the "Rundate" of the POS. Example is a Bar which closes at 02 AM. The "Rundate" for this Day is still the date of the opening, say the Bar opens on June 4th 6 pm, and closes June 5th 2 AM.
"Rundate" now refers to opening Date.
This can become very important in cases where the operation closes around Midnight, as the creation date would here be misleading, depending on whether it closes a few Minutes before or after Midnight.
I have now managed to create a working batch file with the following structure (This one does not yet take the possibility of several *.txt files into consideration, more on this later!)
REN C:\Bartender\Printfiles\*.txt result.txt
C:\POS\Blat\blat.exe C:\POS\PrintFiles\result.txt -tf C:\POS\Blat\recipients.txt -cf C:\POS\blat\ccrecipients.txt -bf C:\POS\Blat\bccrecipients.txt -subject "Your Sales Results from %1" -sig C:\POS\blat\sig.txt -debug -log C:\POS\Blat\log.txt
MOVE C:\Bartender\Printfiles\*.txt C:\Bartender\PrintFiles\Archive\
This file is invoked by the POS Program at successful End of Day routine, and the %1 in the Subject line refers to a parameter consisting of the RUNDATE in Numbers Format (YYYYMMDD) which is passed by the Application to a Batch File named EODEND.BAT.
So far so good, and with your FOR ..DO structure I could extend it for the case of more than one File present.(Which is only possible because of an Error within blat, maybe email server or most likely Interent ! down)
Trouble looms when Errors happen ...
In case of an ERROR of the POS then Blat wont be called, and we have to fix the underlying Error. No an issue we need to discuss here.
But what if the Internet is down?
Blat won't be able to send the File. And the File will be deleted from the Folder.
Here I need to build in some Error handling.
I am thinking of another blat.exe instance EVERYHOUR.BAT that is invoked maybe every hour by Windows Task Scheduler. In normal procedure there won't be any .txt file in the folder, so this task will just quit.
But in the case of an error due to Internet or Mail Server issues in the Original EODEND.BAT, I need EODEND.BAT to exit without running the last command which deletes the .txt File. And then the Batch invoked by Task Scheduler will finally take care of it once Internet is back.As this can take more than one day, there will be more than one .txt file so a FOR .. DO can come handy here. But the %1 won't be available.
Possible Solution: The EVERYHOUR,BAT will use -attach rather and the Subject line will look like: Recovered Sales Results sent %DATE%
What do you think? And how can I modify the Batch Files for correct Error handling?
Thanks a lot for your help!