Tutorials
Nine common jobs, from your first print run to an unattended nightly batch. Every command can be copied and run as is — just replace Office A with your printer name.
01Print a folder, subfolders included
Print every printable file in a folder in file-name order — after a dry run to make sure nothing surprises you.
- Find the printer name
Copy the name exactly as listed and put it after
-prn(in quotes if it has spaces).cmd4printer -options showprnlist - Dry run
Nothing is printed; you see the pages and sheets for each file and any file that cannot be opened.
cmd4printer -src "D:\ToPrint" -prn "Office A" -options scansf:yes sort:name dryrun:yes - Print
Drop
dryrun:yes. The summary line at the end shows submitted, failed and skipped files and the exit code.cmd4printer -src "D:\ToPrint" -prn "Office A" -options scansf:yes sort:name
-src "D:\ToPrint\*.pdf"; several wildcards can follow one -src.02Per-file copies with a CSV list
Different copies, pages or even printers for each file? Put them in a spreadsheet.
- Prepare the list
Create a CSV in Excel or Notepad (an .xlsx works too). The first row holds the column names:
#fileis required,#copies,#pagesand#printerare optional — empty cells fall back to the command line. Relative paths are resolved from the list's folder.#file,#copies,#pages,#printer contracts\purchase.pdf,3,, quote.pdf,1,1, drawings\site-plan.pdf,2,1-2,Plotter A3 acceptance.docx,2,last, - Check the copies with a dry run
cmd4printer -src "@D:\Jobs\list.csv" -prn "Office A" -options dryrun:yes - Print
Rows without
#printergo to the printer given with-prn.cmd4printer -src "@D:\Jobs\list.csv" -prn "Office A" -props duplex:vertical
#printer column only applies when each file is its own job; with spjob:yes everything goes into one job on one printer.03Duplex printing from a specific tray
- Look up the tray names
Tray names come from the printer driver, for example Tray 1, Tray 2 or Manual Feed.
cmd4printer -prn "Office A" -options showtraylist - Long-edge duplex from tray 2
verticalflips on the long edge (like a book),horizontalon the short edge (like a notepad).cmd4printer -src "D:\Reports\*.pdf" -prn "Office A" -props duplex:vertical tray:"Tray 2" - Letterhead for the first page
Load letterhead into tray 1 and use
psspso page 1 comes from tray 1 and the rest from tray 2 — still one print job.cmd4printer -src "D:\Letters\*.docx" -prn "Office A" -props duplex:simplex pssp:"1=Tray 1;2-last=Tray 2"
04Print a booklet
Turn an A4 (or Letter) document into a half-size booklet you can fold and staple.
- Check the sheet count
Each sheet carries two pages per side, and the page count is padded to a multiple of four.
cmd4printer -src "D:\Manual.pdf" -prn "Office A" -multipps enabled:yes booklet:yes -options dryrun:yes - Print
Short-edge duplex is switched on for you; no need to set
duplex. Usebooklet_binding:rightfor right-to-left documents.cmd4printer -src "D:\Manual.pdf" -prn "Office A" -props papersize:A4 -multipps enabled:yes booklet:yes booklet_binding:left - Fold and staple
Fold the whole stack in half and staple along the fold.
hor_pages:2.05Add a watermark and a QR code
Stamp paid invoices with a translucent red “PAID” and add a QR code with the file name in the bottom-right corner.
- Preview by printing to PDF
Use the built-in Microsoft Print to PDF and write the result to a file to check position and color.
cmd4printer -src "D:\Invoices\*.pdf" -prn "Microsoft Print to PDF" -options outputfile:"D:\Preview\{SrcFileName}.pdf" -oper textwatermark text:"PAID" fontsize:36 halign:center valign:center angle:30 color:"r:200,g:0,b:0,a:160" bgcolor:"r:255,g:255,b:255,a:0" -oper barcode format:qr_code contents:"{SrcFileName}" halign:right valign:bottom size:15 - Adjust
a:is the alpha value (0–255);a:0inbgcolormakes the text background transparent; addpages:1to stamp the first page only. - Send it to the real printer
Switch
-prnto your printer and dropoutputfile. You can also save the stamps on the Watermarks page of the settings window so you don't have to type them each time.
06Nightly scheduled printing with archiving
Every day at 22:00, print whatever landed in the inbox folder and archive it, so all that is left in the morning is a glance at the failure list.
- Write a batch file
Save it as
D:\Scripts\nightly-print.bat.min_age:120skips files written in the last two minutes;silent:yes alerts:nokeeps an unattended run free of pop-ups.@echo off rem Nightly print: files in D:\ToPrint are printed and moved to D:\Printed, failures to D:\Failed cmd4printer -src "D:\ToPrint\*.*" -prn "Office A" ^ -props duplex:vertical ^ -options scansf:yes sort:name min_age:120 silent:yes alerts:no log:yes logpath:"D:\PrintLogs" unprinted_files_log:"D:\PrintLogs\failed.txt" ^ -postproc passed:move passed_dir:"D:\Printed" failed:move failed_dir:"D:\Failed" set RC=%ERRORLEVEL% echo %date% %time% exit code %RC%>>"D:\PrintLogs\nightly.txt" exit /b %RC% - Run it once by hand
Run it from Command Prompt and check that the log and archive folders appear as expected.
D:\Scripts\nightly-print.bat - Create the scheduled task
This creates a task for the current user that runs daily at 22:00 (while that user is logged on):
schtasks /Create /TN "Cmd4Printer nightly print" /TR "D:\Scripts\nightly-print.bat" /SC DAILY /ST 22:00To run it while nobody is logged on, open the task in Task Scheduler, choose “Run whether user is logged on or not” and enter the account's password.
C:\Windows\System32\config\systemprofile\Desktop exists (plus C:\Windows\SysWOW64\config\systemprofile\Desktop on 64-bit Windows).07Using exit codes in a batch file
Let the exit code decide what happens next: finish on success, reprint only the failures, or ask a person to check when the result is unknown.
| Exit code | Meaning | What to do |
|---|---|---|
0 | All files were submitted to the print queue | — |
1 | Internal error | Export logs with -options export_path and contact support |
2 | Usage error: wrong switch, value or syntax | Read the allowed values and the example in the error message |
3 | Environment problem: printer, tray, paper or files not found, or the print spooler is stopped | Check names with showprnlist / showtraylist |
4 | Some files failed; the others were submitted | Check unprinted_files_log and reprint only those files |
5 | Submit result unknown; the job may already be queued | Check the print queue before reprinting |
6 | Cancelled (Ctrl+C) | — |
- Batch file
Compare exactly with
if %RC% EQU n;if errorlevel nmeans “n or higher” and is easy to get wrong.@echo off cmd4printer -src "D:\Invoices\*.pdf" -prn "Office A" -options silent:yes unprinted_files_log:"D:\Invoices\failed.txt" set RC=%ERRORLEVEL% if %RC% EQU 0 goto done if %RC% EQU 4 goto partly if %RC% EQU 5 goto check echo Nothing printed: exit code %RC% (2 = bad command, 3 = printer or files not found) exit /b %RC% :partly echo Some files failed; retrying only those in 10 minutes timeout /t 600 /nobreak >nul cmd4printer -src "@D:\Invoices\failed.txt" -prn "Office A" -options silent:yes exit /b %ERRORLEVEL% :check echo Submit result unknown: check the print queue before reprinting exit /b 5 :done echo All files submitted exit /b 0 - PowerShell: read the JSON result
Use
output:jsonwhen you need the state of each file.$r = cmd4printer -src "D:\Invoices\*.pdf" -prn "Office A" -options output:json | Out-String | ConvertFrom-Json "Exit code: " + $r.exitCode $r.items | Where-Object state -eq 'failed' | Select-Object source, @{n='error'; e={$_.error.message}}
08Several printers in one run
Files for different departments go to different printers, or the command is too long for one line: put the commands in a text file and run them with -cmdlines.
- Write the command file
; one command per line, "cmd4printer" may be omitted; lines starting with ; # :: rem are comments -src "D:\Finance\*.pdf" -prn "Finance HP M404" -props duplex:vertical -src "D:\Warehouse\Labels\*.zpl" -prn "Warehouse label printer" -src "D:\Drawings\*.dxf" -prn "Plotter A3" -props papersize:A3 orient:landscape - Run it
Lines run in order; a fatal problem such as a bad command or a missing printer stops the run, and the exit code is the most severe one of all lines.
cmd4printer -cmdlines "D:\Jobs\commands.txt"
09Calling Cmd4Printer from Python, C# and others
Any language that can start a process can drive Cmd4Printer. Pass arguments as a list (don't build quoted strings yourself) and read the exit code or the JSON result.
import json, subprocess
p = subprocess.run(["cmd4printer", "-src", r"D:\Inbox\*.pdf", "-prn", "Office A",
"-options", "output:json"], capture_output=True, text=True, encoding="utf-8")
result = json.loads(p.stdout)
print(p.returncode, result["counts"])var psi = new ProcessStartInfo("cmd4printer",
"-src \"D:\\Inbox\\*.pdf\" -prn \"Office A\" -options silent:yes")
{ UseShellExecute = false, CreateNoWindow = true };
using (var p = Process.Start(psi)) { p.WaitForExit(); Console.WriteLine(p.ExitCode); }