Discussion:
Blat Error Handling
(too old to reply)
manfred.winter@yahoo.com [blat]
2017-11-26 03:24:58 UTC
Permalink
We almost finished our tsk to automatically send result reports files (In either .txt or xlsx formats) to customers of our POS System in Thailand.
I will post more details of our Solution later, but right now we have an issue with Error Handling in Blat.


I demonstrate this here on a Batch file we want to use to send a specific result to a customer. Once working, we will replace the to email, Date and other Data with variable, but here is a basic example with some extra log commands for debug:


rem @echo off
REM New Customers Email
REM V. 1.01


SET LOGFILE=C:\POS\Debug\MailLog.txt


for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"


set "timestamp=%HH%:%Min%"
set "datestamp=%YY%-%MM%-%DD%"


ECHO ----- START ------%datestamp% %timestamp% >> %LOGFILE%
ECHO Now sending Order info to Management >> %LOGFILE%


"C:\POS\Blat\blat.exe" -body "Here are New Order Details from RESTAURANT" -attach "C:\POS\PrintFiles\*.xlsx" -tf "C:\POS\BlatConfig\sprecipients.txt" -subject "RESTURANT Food Orders from %datestamp%" -debug -log %LOGFILE% >> %LOGFILE%


IF !ERRORLEVEL!==13 GOTO :ERROR13
IF !ERRORLEVEL!==12 GOTO :ERROR12
IF !ERRORLEVEL!==5 GOTO :ERROR5
IF !ERRORLEVEL!==4 GOTO :ERROR4
IF !ERRORLEVEL!==3 GOTO :ERROR3
IF !ERRORLEVEL!==2 GOTO :ERROR2
IF !ERRORLEVEL!==1 GOTO :ERROR1





GOTO :SUCCESS


:ERROR13
ECHO ERROR: Error opening temporary file in temp directory >> "%LOGFILE%"
GOTO :FINALISE


:ERROR12
ECHO ERROR: -server or -f options not specified and not found in registry >> "%LOGFILE%"
GOTO :FINALISE


:ERROR5
ECHO ERROR: Error Reading File (message text) >> "%LOGFILE%"
GOTO :FINALISE


:ERROR4
ECHO ERROR: File (message text) not of type FILE_TYPE_DISK >> "%LOGFILE%"
GOTO :FINALISE


:ERROR3
ECHO ERROR: Error reading the file (message text) or attached file >> "%LOGFILE%"
GOTO :FINALISE


:ERROR2
ECHO ERROR: File (message text) does not exist, the server actively denied our connection or the mail server doesn't like the sender name. >> "%LOGFILE%"
GOTO :FINALISE


:ERROR1
ECHO ERROR: File name (message text) not given or Bad argument given, Unable to open SMTP socket, SMTP get line did not return 220, command unable to write to socket, Server does not like To: address or Mail server error accepting message data. >> "%LOGFILE%"


GOTO :FINALISE


:FINALISE
ECHO Error! Error! Error! >>"%LOGFILE%"
GOTO :EXIT


:SUCCESS
ECHO Success! Success! Success! >>"%LOGFILE%"
ECHO Here we delete the sent Files >>"%LOGFILE%"
DEL /F /Q C:\POS\PRINTFILES\*.xlsx" >>"%LOGFILE%"
GOTO :EXIT


:EXIT
ECHO ----- END -------------------- >> "%LOGFILE%"
ECHO.>> "%LOGFILE%"
ECHO.>> "%LOGFILE%"

ECHO.>> "%LOGFILE%"




The batch successfully sends the email with the attachment.
Error handling is also logged correctly (and files not deleted)in case of SMTP server Parameters miscnfigured (WE store the Parameters in Registry; previous issues are resolved)


But in case of missing Internet connection we receive the following Log entry:




----- START ------17-11-26 10:04
Now sending Order info to Management
Blat v3.2.17 (build : Aug 10 2016 22:32:21)
32-bit Windows, Full, Unicode


Read 1 TO address from C:\Bartender\BlatConfig\sprecipients.txt
Error: Connection to server was dropped.
*** Error *** SMTP server error
Error: Not a socket.
Error: Not a socket.
Success! Success! Success!
Here we delete the sent Files

----- END --------------------




Seems we don't catch this specific Error! How can this be resolved?

Manfred
manfred.winter@yahoo.com [blat]
2017-11-26 04:21:58 UTC
Permalink
Thought I should have mentioned that I turned the Laptop into flight Mode to provoke this issue. In case of a Problem with the Router (Forgot to pay my bill ...) Blat exists with Errorcode 1.as expected Unfortunately unplugging the Ethernet Cable or the Wifi USB Stick will most likely have identical consequences, and these will be responsible for 95% of the real life issues at our clients PCs (Forgetting to pay the bill will be the remaining 5%)
manfred.winter@yahoo.com [blat]
2017-11-26 14:23:46 UTC
Permalink
Goedenavond Luko!


Intergrating blat.dll into the POS is currently not an option, as we lack the resources. Lots of other important Development is going on, and we hope to resolve the need for sending automatized results using blat.exe.
The Batch Files are almost completely developed, they encompass all currently necessary cases, and we also compiled an installer for it (Using Innosetup), so distributing the package to our customers isnt a problem.
The only thing we are really stuck at this very moment is the Error handling in case of no available Internet. The Errors we receive in this case are not recognized by the documented Blat Errors, they seem to not return an Errorlevel which we can hanlde. As a result our batch would now inevitably delete unsent reports.
Is this a bug in blat? Or am I missing a documentation?
Can this be resolved using Powershell? Different Errorcodes? I have learnt a fw things in Bath languge now in the last few months, but have no prior experience in Powershell
Rod Carty rod@en-consult.ca [blat]
2017-11-26 14:51:30 UTC
Permalink
I have used error detection with Blat in a batch file. Here is an
example from a batch file. This code is just after Blat is called.

---------------
:: If there is an error, don't delete the alert file
if not errorlevel 0 goto Other
del C:\Scripts\Alert.txt

:Other
----------------

I set this up for pretty much the same reasons as you're talking about,
handling not being able to send because the network is down.
Post by ***@yahoo.com [blat]
Goedenavond Luko!
Intergrating blat.dll into the POS is currently not an option, as we
lack the resources. Lots of other important Development is going on, and
we hope to resolve the need for sending automatized results using blat.exe.
The Batch Files are almost completely developed, they encompass all
currently necessary cases, and we also compiled an installer for it
(Using Innosetup), so distributing the package to our customers isnt a
problem.
The only thing we are really stuck at this very moment is the Error
handling in case of no available Internet. The Errors we receive in this
case are not recognized by the documented Blat Errors, they seem to not
return an Errorlevel which we can hanlde. As a result our batch would
now inevitably delete unsent reports.
Is this a bug in blat? Or am I missing a documentation?
Can this be resolved using Powershell? Different Errorcodes? I have
learnt a fw things in Bath languge now in the last few months, but have
no prior experience in Powershell
Chip chip.programmer@att.net [blat]
2017-11-26 15:16:39 UTC
Permalink
I am away from my computer for the weekend, but here is a thought.  Add the following line immediately after calling Blat:

echo Blat returned error value %errorlevel%

The line above should help you determine which value to expect with no internet.
-- 
Chip

<div>-------- Original message --------</div><div>From: "***@yahoo.com [blat]" <***@yahoogroups.com> </div><div>Date:11/26/2017 7:23 AM (GMT-07:00) </div><div>To: ***@yahoogroups.com </div><div>Subject: Re: [blat] Blat Error Handling </div><div>
</div>

Goedenavond Luko!

Intergrating blat.dll into the POS is currently not an option, as we lack the resources. Lots of other important Development is going on, and we hope to resolve the need for sending automatized results using blat.exe.
The Batch Files are almost completely developed, they encompass all currently necessary cases, and we also compiled an installer for it (Using Innosetup), so distributing the package to our customers isnt a problem.
The only thing we are really stuck at this very moment is the Error handling in case of no available Internet. The Errors we receive in this case are not recognized by the documented Blat Errors, they seem to not return an Errorlevel which we can hanlde. As a result our batch would now inevitably delete unsent reports.
Is this a bug in blat? Or am I missing a documentation?
Can this be resolved using Powershell? Different Errorcodes? I have learnt a fw things in Bath languge now in the last few months, but have no prior experience in Powershell
manfred.winter@yahoo.com [blat]
2017-11-26 15:47:12 UTC
Permalink
Found the mistake ... copied the error handling from another batch file where it was executed inside a loop, therefore the!ERRORLEVEL!, changed that to %, now runs like a charm. Thanks a lot, looks like the job is basically done!
Will post our solution involving blat as soon as I am certain I did not build in another bug ...
Continue reading on narkive:
Loading...