Differences

This shows you the differences between the selected revisions of the page.

2020-12-23 2021-03-31
automatically using target article title for link anchor (martin) simplify by factoring out the email sending to separate guide + using code blocks for nicer code (martin)
Line 125: Line 125:
  * Save and inspect output of the script. Use [[executables|output redirection]].   * Save and inspect output of the script. Use [[executables|output redirection]].
-Once you find out what was the result of the script, you can perform any action you like. E.g. after evaluating exit code of WinSCP, you can send a "success" or "error" email. For that use any command-line email client you like, e.g. [[https://www.glob.com.au/sendmail/|sendmail]].((When installing sendmail, you can ignore all references to ''/usr/lib/'' (or ''c:\usr\lib'') directories in its installation instructions, as you will be running ''sendmail.exe'' directly from a Windows batch file. Just place sendmail files to any convenient location, e.g. along with WinSCP.))+Once you find out what was the result of the script, you can perform any action you like: print a message, [[script_email|send an email]], etc.
You should also make the batch file indicate a result in its exit code, particularly if it is called from some parent system (for example [[guide_ssis|SSIS]]). You should also make the batch file indicate a result in its exit code, particularly if it is called from some parent system (for example [[guide_ssis|SSIS]]).
Line 132: Line 132:
<code batch> <code batch>
-winscp.com /ini=nul /script=example.txt +winscp.com /ini=nul /log=example.log /script=example.txt 
-if %ERRORLEVEL% neq 0 goto error +if %ERRORLEVEL% equ 0 ( 
- +··echo Success 
-echo Success +  exit /b 0 
-sendmail.exe -t < success_mail.txt +) else ( 
-exit /b 0 +··echo Error! 
- +  exit /b 1 
-:error +)
-echo Error! +
-sendmail.exe -t < error_mail.txt +
-exit /b 1+
</code> </code>
A similar error handling is used in [[ui_generateurl|the batch file template]] that WinSCP can generate for you. A similar error handling is used in [[ui_generateurl|the batch file template]] that WinSCP can generate for you.
- 
-Where for example content of ''success_mail.txt'' may be: 
-<code> 
-From: script@example.com 
-To: me@example.com 
-Subject: Success 
- 
-The files were uploaded successfully. 
-</code> 
//If you require checking results of each command individually, you should better use the [[library|WinSCP .NET assembly]]. Alternatively, see the guide [[guide_automation_advanced|*]] for examples of checking script results (including XML log parsing) using more powerful languages and the guide to [[guide_interpreting_xml_log|*]] using C# language.// //If you require checking results of each command individually, you should better use the [[library|WinSCP .NET assembly]]. Alternatively, see the guide [[guide_automation_advanced|*]] for examples of checking script results (including XML log parsing) using more powerful languages and the guide to [[guide_interpreting_xml_log|*]] using C# language.//

Last modified: by martin