Hello world/Line printer: Difference between revisions

From Rosetta Code
Content added Content deleted
(J)
m (removed quotation mark from batch; various other minor clean-up)
Line 5: Line 5:


{{works with|QBasic}}
{{works with|QBasic}}

{{works with|ZX Spectrum Basic}}
{{works with|ZX Spectrum Basic}}

<lang qbasic>LPRINT "Hello World!"</lang>
<lang qbasic>LPRINT "Hello World!"</lang>


=={{header|Batch File}}==
=={{header|Batch File}}==


<lang dos>ECHO Hello world!">PRN</lang>
<lang dos>ECHO Hello world!>PRN</lang>


=={{header|J}}==
=={{header|J}}==
Line 31: Line 33:


=={{header|Tcl}}==
=={{header|Tcl}}==

On Unix only:
===[[Unix]]===
<lang tcl>exec lp << "Hello World!"</lang>
<lang tcl>exec lp << "Hello World!"</lang>
or
<lang tcl>set f [open |lp w]
<lang tcl>set f [open |lp w]
puts $f "Hello World!"
puts $f "Hello World!"
close $f</lang>
close $f</lang>

On Windows only:
===[[Windows]]===

<lang tcl>set f [open prn w]
<lang tcl>set f [open prn w]
puts $f "Hello World!"
puts $f "Hello World!"
Line 49: Line 53:


{{works with|POSIX}}
{{works with|POSIX}}

Alternately, there are the character devices <tt>/dev/lp0</tt>, <tt>/dev/lp1</tt>, <tt>/dev/lpN</tt> and so on which correspond to line printers (if there are any attached to the system). Data written to these devices is sent to attached printers.
Alternately, there are the character devices <tt>/dev/lp0</tt>, <tt>/dev/lp1</tt>, <tt>/dev/lpN</tt> and so on which correspond to line printers (if there are any attached to the system). Data written to these devices is sent to attached printers.

<lang bash>echo 'Hello World' > /dev/lp0</lang>
<lang bash>echo 'Hello World' > /dev/lp0</lang>

Revision as of 05:08, 5 October 2010

Task
Hello world/Line printer
You are encouraged to solve this task according to the task description, using any language you may know.

Cause a line printer attached to the computer to print a line containing the message Hello World!

BASIC

Works with: QBasic
Works with: ZX Spectrum Basic

<lang qbasic>LPRINT "Hello World!"</lang>

Batch File

<lang dos>ECHO Hello world!>PRN</lang>

J

<lang j>require'print' print'Hello world!'</lang>

PureBasic

Library: PureLPRINT

<lang PureBasic>MyPrinter$ = LPRINT_GetDefaultPrinter() If LPRINT_OpenPrinter(MyPrinter$)

 If LPRINT_StartDoc("Printing a RC-Task")
   LPRINT_Print(Chr(27) + "E") ; PCL reset for HP Printers
   LPRINT_PrintN("Hello World!")
   LPRINT_NewPage()
   LPRINT_EndDoc()
 EndIf
 LPRINT_ClosePrinter()  

EndIf</lang>

Tcl

Unix

<lang tcl>exec lp << "Hello World!"</lang> <lang tcl>set f [open |lp w] puts $f "Hello World!" close $f</lang>

Windows

<lang tcl>set f [open prn w] puts $f "Hello World!" close $f</lang>

UNIX Shell

Works with: Bourne Shell

<lang bash>echo 'Hello World!'|lp</lang>

Works with: POSIX

Alternately, there are the character devices /dev/lp0, /dev/lp1, /dev/lpN and so on which correspond to line printers (if there are any attached to the system). Data written to these devices is sent to attached printers.

<lang bash>echo 'Hello World' > /dev/lp0</lang>