Question

I need to send an email to a submitter if a copy fails. For example my code is this:

echo F|xcopy "%src_dir%" "%tgt_dir%" 1>>"%logfile%" 2>&1

echo Success: Polysystems Directory was successfully promoted. 1>>"%logfile%" 2>&1

My output is this:

File not found - LTCG_v2306_02_07_2014_854.pfd

0 File(s) copied

Success: Polysystems Directory was successfully promoted.

If "File not found" is returned I need to send a failure email instead of the success email. Is there a way to store this message in a variable to compare it to? or another way of accomplishing this?

Was it helpful?

Solution

You should not store the message, because there's no guarantee that it will stay the same. Use instead exit codes:

0 - Files were copied without error.
1 - No files were found to copy.
2 - The user pressed CTRL+C to terminate xcopy.
4 - Initialization error occurred. There is not enough memory or disk space, or you entered an invalid drive name or invalid syntax on the command line.
5 - Disk write error occurred.

thus in case of "File not found", xcode will return exit code '1'. Then you can send your email.

It could be, for example, something like this this could be an example:

set my_errorlevel=0
xcopy....
if ERRORLEVEL 1 (
   set my_errorlevel=%errorlevel%
) else echo Success: Polysystems Directory was successfully promoted. 1>>"%logfile%" 2>&1
...
exit /b %my_errorlevel%
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top