Error suppression

I have a script that monitors certain files on a shared network drive that are created & deleted by other processes running on the same or different hosts from the monitoring script.
Because this monitoring script runs independently of the processes that create & delete the files of interest, I've run into a timing issue with the following command:
if exist "%file" set age=%@fileage["%file"]
The symptom is that the script line will occasionally throw an error that "The system cannot find the file specified."

This indicates to me that the file exists at the time the condition is checked, but is deleted by the time the function can be executed. I've tried to add some redirection to the command (set age=%@fileage["%file"] 2> nul:) to suppress the error, but that doesn't appear to work.

I don't want to suppress the entire batch file's use of STDERR, just the one line where the error condition isn't relevant. Is there some way to make the function "quiet"?
 

samintz

Scott Mintz
May 20, 2008
1,514
18
Solon, OH, USA
I don't know if the inability to redirect the error message is an anomaly
or a feature. However, I did find that using ON ERROR REM allows you to
suppress the error.

I wrote a BTM script:
on error rem
echo %@fileage[%1]

I get no error text with an invalid input.

-Scott

millardjk <> wrote on 04/16/2010 03:10:39 PM:


> I have a script that monitors certain files on a shared network
> drive that are created & deleted by other processes running on the
> same or different hosts from the monitoring script.
> Because this monitoring script runs independently of the processes
> that create & delete the files of interest, I've run into a timing
> issue with the following command:if exist "%file" set
age=%@fileage["%file"]

>
> The symptom is that the script line will throw an error that "The
> system cannot find the file specified."
>
> This indicates to me that the file exists at the time the condition
> is checked, but is deleted by the time the function can be executed.
> I've tried to add some redirection to the command (set age=%
> @fileage["%file"] 2> nul:) to suppress the error, but that doesn't
> appear to work.
>
> I don't want to suppress the entire batch file's use of STDERR, just
> the one line where the error condition isn't relevant. Is there some
> way to make the function "quiet"?
>
>
>
>
 

samintz

Scott Mintz
May 20, 2008
1,514
18
Solon, OH, USA
Alternatively, you can assign a specific value to your age variable
instead of the REM command.

on error set age=0
set age=%@fileage[%1]
on error
echo age is %age

-Scott

samintz <> wrote on 04/16/2010 03:49:59 PM:


> I don't know if the inability to redirect the error message is an
anomaly

> or a feature. However, I did find that using ON ERROR REM allows you to


> suppress the error.
>
> I wrote a BTM script:
> on error rem
> echo %@fileage[%1]
>
> I get no error text with an invalid input.
>
> -Scott
>
> millardjk <> wrote on 04/16/2010 03:10:39 PM:
>
>
>
> ---Quote---
> > I have a script that monitors certain files on a shared network
> > drive that are created & deleted by other processes running on the
> > same or different hosts from the monitoring script.
> > Because this monitoring script runs independently of the processes
> > that create & delete the files of interest, I've run into a timing
> > issue with the following command:if exist "%file" set
> ---End Quote---
> age=%@fileage["%file"]
>
>
> ---Quote---
> >
> > The symptom is that the script line will throw an error that "The
> > system cannot find the file specified."
> >
> > This indicates to me that the file exists at the time the condition
> > is checked, but is deleted by the time the function can be executed.
> > I've tried to add some redirection to the command (set age=%
> > @fileage["%file"] 2> nul:) to suppress the error, but that doesn't
> > appear to work.
> >
> > I don't want to suppress the entire batch file's use of STDERR, just
> > the one line where the error condition isn't relevant. Is there some
> > way to make the function "quiet"?
> >
> >
> >
> >
> ---End Quote---
>
>
>
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,496
91
Albuquerque, NM
prospero.unm.edu
I have a script that monitors certain files on a shared network drive that are created & deleted by other processes running on the same or different hosts from the monitoring script.
Because this monitoring script runs independently of the processes that create & delete the files of interest, I've run into a timing issue with the following command:
if exist "%file" set age=%@fileage["%file"]
The symptom is that the script line will occasionally throw an error that "The system cannot find the file specified."

This indicates to me that the file exists at the time the condition is checked, but is deleted by the time the function can be executed. I've tried to add some redirection to the command (set age=%@fileage["%file"] 2> nul:) to suppress the error, but that doesn't appear to work.

I don't want to suppress the entire batch file's use of STDERR, just the one line where the error condition isn't relevant. Is there some way to make the function "quiet"?

TCC does variable expansion (including functions) before it checks for redirections. Otherwise, you wouldn't be able to redirect to a file specified by a variable.

You can use command grouping to make the redirection happen first:

Code:
set age=
( set age=%@fileage["%file"] ) >& nul
 
TCC does variable expansion (including functions) before it checks for redirections. Otherwise, you wouldn't be able to redirect to a file specified by a variable.

You can use command grouping to make the redirection happen first:

Code:
set age=
( set age=%@fileage["%file"] ) >& nul

While I like the simplicity of this technique, Scott's technique using "on error" is more "readable" for the other folks on my team that may have to edit this code in the future (they don't spend quite the same amount of time writing BTMs as I do).
 
Alternatively, you can assign a specific value to your age variable
instead of the REM command.

on error set age=0
set age=%@fileage[%1]
on error
echo age is %age

-Scott
Nice. I'm going to use this technique with a slight variation:
Code:
on error REM suppress "file not found" error in @fileage[]
if exist "%file" set age=%@fileage["%file"]
on error
iff defined age .and. %age lt %limit then
...
endiff
 
Similar threads
Thread starter Title Forum Replies Date
C Copy (sys) error Support 3
T Error: This page can’t be displayed Make sure the web address //ieframe.dll/dnserrordiagoff.htm# is correct. Support 8
kb6ojs How to? "Specified Account Already Exists" error installing TCMD v27 Support 12
samintz How to? Abort on error DO loop Support 10
mfarah Fixed The DATE command produces the wrong error message. Support 1
vefatica ON ERROR terminates DO loop. Support 0
C Google intregration error Support 4
C FB intregration error Support 0
gworley rd (Remove Directory) gives interesting error: Support 2
D How to? Skip removing directory (RMDIR) without error message Support 2
Dmitry L. Kobyakov Documentation Error in the Help: the WINDOW command Support 0
M Strange error messages from TCC in FTP copy Support 7
vefatica Error message from TOUCH Support 2
R FIND command error Support 9
fpefpe Python dll error Support 3
D error in help documentation? Support 0
R FOR usage error from TCC but not from CMD Support 16
K_Meinhard Help file error Support 1
X small translation error. Support 0
W pdir returns diff results between tcc and tcmd - one is an error msg Support 5
Dmitry L. Kobyakov From old version: had the setup's error been corrected? Support 6
vefatica Why no error message? Support 2
vefatica ON ERROR and pipes? Support 8
MickeyF Why does this batch file give me 'unknown command "else"' error? Support 17
Joe Caverly TASKDIALOG Help link error Support 1
J Error "Contents lost before copy" Support 3
vefatica What's causing this error? Support 4
vefatica Error 203? Support 4
C Activation Error. Support 2
J Error running Python at command line Support 9
Joe Caverly PSHELL Error? Support 16
M Fixed PSHELL command returns error Support 2
vefatica REGDIR, strange error message Support 7
O Error in plugin /u Support 2
O TPIPE: Error -Can´t access textpipeengine.dll Support 24
fpefpe How to? script error Support 1
fpefpe How to? script error Support 0
D Error 0xc0000142 and FAR Manager Support 10
F Powershell call fails with "Scripting Integrator 2016 (PowerShell)" license error Support 9
cgunhouse FTP Error Support 5
C How to? Error updating from 20.00.16 to 20.00.21 Support 10
vefatica Missing post and security error Support 4
samintz Documentation TCANSI error Support 8
vefatica WAD ON ERROR GOTO ... Support 11
dcantor Documentation Documentation error in UNSET Support 0
vefatica Error updating Support 2
C tpipe /simple=28 error Support 5
B Fixed Error messages from TCMD.INI Support 2
Alpengreis [Bug?] View (V) Prefs Error (TC 18.00.27 x64) Support 4
Bill de Haan HTTP Protocol error. 407 Proxy Authentication Required. Support 3

Similar threads