• Contact
  • Company
  • Login / My Account
  • Shopping Cart (0)
Document Conversion Made Easy!
Peernet Menu
  • Products
      • Virtual Printers
        • tiff-image-printer-iconTIFF Image Printer – Create TIFF Images
        • raster-image-printer-iconRaster Image Printer – Create TIFF, PDF, JPEG, etc.
        • pdf-image-printer-iconPDF Image Printer – Create Searchable PDF
      • PDF Editor
        • pdf-creator-plus-iconPDF Creator Plus – Merge, Edit, Create Searchable PDF
      • Batch Converters
        • document-conversion-service-iconDocument Conversion Service – Unattended 24/7 Batch Converter
        • file-conversion-center-iconFile Conversion Center – Desktop Batch Converter
      • Reporting Software
        • peernet-reports-iconPEERNET Reports – Barcode, Report and Label Software
      • enterprise-licensingEnterprise Licensing for your Corporation
      • discounts-multiple-licensesDiscounts for Purchasing Multiple Licenses
      • distribute-bundle-peernet-softwareDistribute PEERNET Software Bundled with your Product
  • Purchase
      • Purchase Virtual Printers
        • tiff-image-printer-iconTIFF Image Printer – Create TIFF Images
        • raster-image-printer-iconRaster Image Printer – Create TIFF, PDF, JPEG etc.
        • pdf-image-printer-iconPDF Image Printer – Create Searchable PDF
      • Purchase PDF Editor
        • pdf-creator-plus-iconPDF Creator Plus – Merge, Edit, Create Searchable PDF
      • Purchase Batch Converters
        • document-conversion-service-iconDocument Conversion Service – Unattended 24/7 Batch Converter
        • file-conversion-center-iconFile Conversion Center – Desktop Batch Converter
      • Purchase Reporting Software
        • peernet-reports-iconPEERNET Reports – Barcode, Report and Label Software
      • peernet-online-store-purchase-optionsPurchase Options
      • peernet-software-license-levelsLicense Levels
      • peernet-software-purchase-resellerFind Resellers
      • peernet-software-sales-faqsSales FAQ
  • Learn & Support
        • peernet-help-centerTutorials
          • Learn the Basics or Go Beyond with Video Tutorials, FAQs and Guides

            At PEERNET we pride ourselves on providing the best support and the fastest response times in the industry.
          • Select Software Tutorials:
              • tiff-image-printer-iconTIFF Image Printer
              • raster-image-printer-iconRaster Image Printer
              • pdf-image-printer-iconPDF Image Printer
              • pdf-creator-plus-iconPDF Creator Plus
              • document-conversion-service-iconDocument Conversion Service
              • file-conversion-center-iconFile Conversion Center
              • peernet-reports-iconPEERNET Reports
        • peernet-software-faqsSales FAQ
          • Popular Topics

            Find all the answers you need to our most frequently asked questions.
              • Download & Install
                • How do I download software I already purchased?
              • Purchasing & Renewing
                • How do I purchase PEERNET software?
                • What license level do I need?
                • How do I add licenses to an existing serial number?
                • How do I renew my annual subscription?
              • Licensing & Operating
                • How do I activate my new PEERNET software?
                • How do I activate my software without an internet connection?
                • Where do I find my serial number?
                • How do I move my software to a new computer?
                • How do I update/upgrade my software to the latest release?
            • Read all Sales FAQs
  • Blog
  • Menu Menu

Running Post-Process Commands with Watch Folder Service

Introduced in Document Conversion Service 3.0.010, and updated in version 3.0.015, the Watch Folder Service can now run post-process commands for each file it finds to convert. These commands can be batch files or other executables.

You can specify separate commands to run for when the conversion succeeds and when it fails. When the conversion is successful, we can run the command a single time, or run the command against each file created by the conversion. If the conversion fails, then we run the command against the original source file.

Trial Download
View Product

A sample scenario of how this could be useful would be a watched folder set up to run a command to upload all newly converted files to an FTP server or a web server when they are successfully converted, and to send an email with the name of the original file in the case of a conversion failing.

Running a Command on Success

DCS versions 3.0.010 – 3.0.014 will run this command for each file we create. This means the command will be run multiple times when creating single-paged file formats such as JPEG and serialized TIFF from multipaged documents.

Starting with version 3.0.015 the command is called once and it does not run until the file is converted and the created file, or files, have been copied to the output folder. If desired, there is an option to return to the previous behavior and run the command individually for each file created.

Also added in 3.0.015 is the option to create a Unicode text file containing a list of the created files. This text file is placed in the OutputFolder location with the created files. You are responsible for deleting this file when you are done with it.

The following variables for are available to use in the Success command line parameters, and are replaced with their appropriate values when the command runs.

  • $(OutputFilePath) – The full path to the converted file. When creating serialized output this is last file created in the set unless RunAtEnd.Success.RunForEachFile is true, in which case it is the full path to the converted file.
  • $(SourceFileName) – The file name of the original file.
  • $(OutputFileList) – Only valid when RunAtEnd.Success.CreateOutputFileList is set to true, this variable is the full path to a Unicode text file containing a list of all the files created, one per line. This list can be a single file, for multipaged conversion, or many files in the case of serialized conversion.
  • $(OutputFileNumber) – The numerical index of the file being processed in the run command. Index starts at 1.
  • $(OutputFileNumberCount) – This is the total number of files created.

Running a Command on Fail

This command is run when a file conversion fails. The variables below are available to use in the Fail command line parameters, and are replaced with their appropriate values when the command runs.

  • $(FailedFilePath) – The path to the original file in its failed location, usually the FailedFolder.
  • $(SourceFileName) – The file name of the original file.

Waiting for a Command to Finish

When running a command, the Watch Folder will either wait for the command to complete or not wait for it to complete and will move on to the next file immediately. The default action is not to wait for the command to complete.

When waiting for the command to complete, a maximum wait time controls when to stop the running command if it has not completed in a timely fashion. This timeout can be increased but it cannot be set to 0 and it is enforced. The default timeout is three minutes.

  • DoNotWait – does not wait for the command to complete. (Default)
  • WaitForCompletion – wait for the command to complete before continuing.
  • WaitWithExitCode – waits for the command to complete and emits the exit code in the log.

Sample Usage

Below is a sample post-conversion command setup that uploads any successfully created files to another location using command line FTP, and sends a notification email using a SMTP via a PowerShell script for any files that fail to convert.

There are many ways to do these two tasks. The scripts below are just one approach and are only provided to demonstrate setting up post-process commands. Please test accordingly if you plan to use them in a production environment.

The FTP Upload Batch File

The batch file, UPLOAD.BAT, shown here takes a single argument, the full path to the file to upload, which we pass to it using the command line variable $(OutputFilePath).

It creates a data file that is passed to Microsoft’s built-in FTP utility using its scripting option. As the Watch Folder is converting files in parallel, we use the %random% environment variable to create a uniquely named input file for each converted file.

In the batch file, replace the MyUserName, MyPassword and SERVERNAME.COM with the correct values for your ftp server, and set the upload location to the path where you want the files to be stored.

@echo off
REM 
REM This code is distributed in the hope that it will be useful, but WITHOUT 
REM ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
REM FITNESS FOR A PARTICULAR PURPOSE.
REM 
REM Usage: 
REM     UPLOAD.BAT  

IF [%1]==[] GOTO NO_ARGUMENTS

REM Create a random name
set FTPCMDNAME=ftpcmd%random%.dat

REM Replace the values below with your user name, password and server.
set USERNAME=MyUserName
set PASSWORD=MyPassword
set SERVER=SERVERNAME.COM

REM Set your upload location here
set LOCATION=/ftp/SalesFiles/

REM Create the ftp script
echo user %USERNAME%> %FTPCMDNAME%
echo %PASSWORD%>> %FTPCMDNAME%
echo bin>> %FTPCMDNAME%
echo cd %LOCATION%>> %FTPCMDNAME%
echo put %1>> %FTPCMDNAME%
echo quit>> %FTPCMDNAME%

REM Upload the  file
ftp -n -s:%FTPCMDNAME% %SERVER%

REM Clean up
del %FTPCMDNAME%

REM Uncomment if you want to move uploaded files to a different location.
REM move %1 C:\FilesUploaded

GOTO DONE

:NO_ARGUMENTS
REM Add your own code here to handle missing arguments.
ECHO Missing Arguments
ECHO Usage: UPLOAD.BAT ""

:DONE

The SMTP Email Batch File
Two files are used to send the email – a batch file, FAILED.BAT, that takes the path to the failed file and sends the email via SMTP using a PowerShell script.

The batch file shown here takes a single argument, the full path to the failed file, which we pass to it using the command line variable $(FailedFilePath). This path is then passed to the PowerShell script.

@echo off
REM 
REM This code is distributed in the hope that it will be useful, but WITHOUT 
REM ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
REM FITNESS FOR A PARTICULAR PURPOSE.
REM 
REM Usage: 
REM     FAILED.BAT ""

IF [%1]==[] GOTO NO_ARGUMENTS

REM Set path to the script here
SET PS_SCRIPT="C:\ScriptFiles\sendemail.ps1"

Powershell.exe -executionpolicy remotesigned -File %PS_SCRIPT% -FailedPath "%1"
GOTO DONE

:NO_ARGUMENTS
REM Add your own code here to handle missing arguments.
ECHO Missing Arguments
ECHO Usage: FAILED.BAT ""

:DONE

The PowerShell script to send the email is listed below and needs to be updated to use your SMTP credentials. Make your changes then save this file in the location you specified for the PS_SCRIPT variable in the batch file above. For our example, we would save it as C:\ScriptFiles\sendemail.ps1.

# This code is distributed in the hope that it will be useful, but WITHOUT 
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
# FITNESS FOR A PARTICULAR PURPOSE.
#
param([String]$FailedPath)
#
# Replace these values with your SMTP credentials
$SMTPServer = "smtp.gmail.com"
$SMTPPort = '587'
$EmailFrom = "[email protected]"
$Password = "YourGmailPassword"
$EmailTo = "[email protected]"
$Subject = "File Failed"
$Body = "The following file has failed to convert : " + $FailedPath
#
# Create the mail object and sent the email
$SMTPClient = New-Object Net.Mail.SmtpClient($SMTPServer, $SMTPPort)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential($EmailFrom, $Password );
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)

Configuring the Watch Folder for Post Process Commands

Each watch folder definition has separate sections for enabling and running post process commands for conversion success and failure.

Take note of the usage of HTML escape characters for the quotation marks around the variable names in the parameters in order to pass the parameters with enclosing quotes.

In the configuration below, the two batch files, UPLOAD.BAT and FAILED.BAT, and the PowerShell script sendemail.ps1 above are all located in the folder C:\ScriptFiles.

Running UPLOAD.BAT for each successful file:
To run a command on success, set RunAtEnd.Success.Enabled to true.

We want to upload all converted files to an FTP server. The default behaviour is to run this command only once, after the created file is copied to the OutputFolder. This works as expected when creating multipaged formats such as TIFF or PDF.

To handle creating single-paged files formats such as JPG images, or serialized TIFF images where each page is its own file, we need to set RunAtEnd.Success.RunForEachFile to true.

Enter the full path to the command to run, C:\ScriptFiles\UPLOAD.BAT, into RunAtEnd.Success.Command.

The arguments to the UPLOAD.BAT batch file is the full path to the created file. We pass this using the $(OutputFilePath) variable set in RunAtEnd.Success.Parameters. To handle paths with spaces, use the HTML escape characters for quotation marks.

Running FAILED.BAT for conversion failure:

To run a command on failure, set RunAtEnd.Fail.Enabled to true.

Enter the full path to the command to run, C:\ScriptFiles\FAILED.BAT, into RunAtEnd.Fail.Command.

The arguments to the FAILED.BAT batch file is the full path to the original file that failed to convert. We pass this using the $(FailedPath) variable set in RunAtEnd.Fail.Parameters. To handle paths with spaces, use the HTML escape characters for quotation marks.

Watch more Document Conversion Service Tutorials


Getting Started Series

Install DCS
Configure DCS
Start & Verify DCS
Configure Watch Folder
Watch Folder Settings Overview

Watch Folder Service

Watching Multiple Input Folders
Clustering Setup
Change the Logon Account
Extract MSG Attachments
Run Post Command

Resources

Why DCS Is Right For You
Ways DCS Can Work For You
The DCS License Level You Need

More Tutorials

Creating and Editing Conversion Profiles
Troubleshooting with the Logging Console
Activate License

https://www.peernet.com/wp-content/uploads/dcs-command-line-tools-post.png 600 900 Robert Massart https://www.peernet.com/wp-content/uploads/peernet-logo.png Robert Massart2017-01-27 13:18:452024-06-24 07:45:14Running Post-Process Commands with Watch Folder Service
  • Document Conversion Service
  • TIFF Image Printer
  • Raster Image Printer
  • PDF Image Printer
  • PDF Creator Plus
  • File Conversion Center
  • PEERNET Reports
Search Search

Recent Posts

  • PNSrv11Lib to PNSrv12Lib: Migration Made Easy
  • Migrating to Version 12: Compatibility Mode Quick Start Guide
  • Well Logs: Stitch PDF Pages into a Continuous TIFF Image
  • Dynamic Stamp Content
  • Convert to PDF: The Power of On-Premise PDF Creation

INTERESTING LINKS

Below are some interesting links for you! Enjoy your stay :)

RSS Feed Logo RSS Feed Logo Subscribeto RSS Feed

OUR PRODUCTS

  • Document Conversion Service
  • TIFF Image Printer
  • Raster Image Printer
  • PDF Image Printer
  • PDF Creator Plus
  • File Conversion Center
  • PEERNET Reports

LATEST NEWS

  • PNSrv11Lib to PNSrv12Lib: Migration Made EasyMarch 14, 2025 - 2:10 pm
  • Migrating to Version 12: Compatibility Mode Quick Start GuideMarch 14, 2025 - 2:09 pm
  • Well Logs: Stitch PDF Pages into a Continuous TIFF ImageMarch 14, 2025 - 2:08 pm
  • Dynamic Stamp ContentNovember 4, 2024 - 4:47 pm

BUSINESS INFORMATION

Toll Free: 1-800-883-7980 North America

Tel: 1-613-224-6894

Our office hours are Monday to Friday, from 0900 hrs to 1700 hrs, Eastern Standard Time.

Email Address: [email protected]
Copyright © 1997-2026. All rights reserved. Terms and Conditions | Disclaimer | Privacy Policy | Trademarks.
PEERNET® is a registered trademark of PEERNET Inc.
  • Link to Youtube
  • Link to Rss this site
  • Products
  • Purchase
  • Company
  • Contact
Link to: Batch Conversion: Optimizing For Throughput and Failover Capabilities Link to: Batch Conversion: Optimizing For Throughput and Failover Capabilities Batch Conversion: Optimizing For Throughput and Failover Capabilities Link to: Configure DCS and Watch Folder for Optimal Performance Link to: Configure DCS and Watch Folder for Optimal Performance Configure DCS and Watch Folder for Optimal Performance
Scroll to top Scroll to top Scroll to top