How to print to default printer in a console app

Can anyone suggest me a way to print to default printer from console application. I tried to use OpenPrinter and while compilation it says “This item does not exists” whereas no where in the doc it says this command is only for desktop apps. Is there any other method to use in console app other than plugins or declares.

on mac and linux you can use lp

NAME

   lp - print files

SYNOPSIS

   lp  [  -E  ]  [ -U username ] [ -c ] [ -d destination[/instance] ] [ -h
   hostname[:port] ] [ -m ] [ -n num-copies ] [ -o option[=value] ]  [  -q
   priority  ] [ -s ] [ -t title ] [ -H handling ] [ -P page-list ] [ -- ]
   [ file(s) ]
   lp [ -E ] [ -U username ] [ -c ] [ -h hostname[:port] ] [ -i job-id ] [
   -n num-copies ] [ -o option[=value] ] [ -q priority ] [ -t title ] [ -H
   handling ] [ -P page-list ]

DESCRIPTION

   lp submits files for printing or alters a pending job.  Use a  filename
   of "-" to force printing from the standard input.

THE DEFAULT DESTINATION
CUPS provides many ways to set the default destination. The LPDEST and
PRINTER environment variables are consulted first. If neither are set,
the current default set using the lpoptions(1) command is used, fol-
lowed by the default set using the lpadmin(8) command.

on windows you can use lpr

lpr works great on Win 7 and up. You do not need to copy it. In Control Panel, go to “turn windows features on or off” and make sure “print and document services” are installed.
To use lpr to send a file to printer that uses the RAW protocol, the syntax is:
lpr -S -P raw

e.g.
lpr -S 192.168.11.118 -P raw postscript.ps

Mac? Windows? Linux?

NSPrintOperationMBS even works on Mac console app as far as I know.

Its actually for Windows but good if it can work cross platform.

Please check all the print stuff we have for windows in the MBS Xojo Win Plugin:

https://www.monkeybreadsoftware.net/pluginpart-windowsprint.shtml

especially WindowsAddPrintJobMBS class was made to send print data directly to a printer.