Hello world/Line printer: Difference between revisions

m
No edit summary
m (→‎{{header|Wren}}: Minor tidy)
 
(18 intermediate revisions by 12 users not shown)
Line 21:
{{trans|Python}}
 
<langsyntaxhighlight lang="11l">V lp = File(‘/dev/lp0’, ‘w’)
lp.write("Hello World!\n")
lp.close()</langsyntaxhighlight>
 
=={{header|360 Assembly}}==
<langsyntaxhighlight lang="360asm">HELLO CSECT
PRINT NOGEN
BALR 12,0
Line 38:
L1 DS 0CL133
HW DC C'Hello World!'
END HELLO</langsyntaxhighlight>
 
=={{header|Action!}}==
<langsyntaxhighlight Actionlang="action!">Proc Main()
Open(1,"P:",8,0)
PrintDE(1,"HELLO WORLD!")
Close(1)
Return
</syntaxhighlight>
</lang>
 
=={{header|Ada}}==
===[[Unix]]===
Assuming that the line printer is attached to /dev/lp0
<syntaxhighlight lang="ada">
<lang Ada>
with Ada.Text_IO; use Ada.Text_IO;
 
Line 69:
Close (Printer);
end Print_Line;
</syntaxhighlight>
</lang>
 
=={{header|ALGOL 68}}==
Line 77:
remote printer interfaced via CUPS. Extending it to other
environments is left as an exercise for the reader.
<langsyntaxhighlight lang="algol68">
BEGIN
STRING printer name = "/dev/lp0";
Line 97:
FI
END
</langsyntaxhighlight> {{out}}
<pre>
Can't contact line printer on /dev/lp0
Line 107:
Assumes a printer card is installed in the Apple II's number 1 expansion slot.
 
<langsyntaxhighlight lang="basic">
PR#1
PRINT "HELLO WORLD!"
</syntaxhighlight>
</lang>
 
=={{header|Arturo}}==
<syntaxhighlight lang="arturo">write "/dev/lp0" "Hello World\n"</syntaxhighlight>
 
=={{header|AutoHotkey}}==
<syntaxhighlight lang="autohotkey">
<lang AutoHotkey>
Fileappend, Hello World!, print.txt
Run, print "print.txt"
</syntaxhighlight>
</lang>
 
=={{header|AWK}}==
Unix / Linux:
<syntaxhighlight lang="awk">
<lang AWK>
BEGIN { print("Hello World!") >"/dev/lp0" }
</syntaxhighlight>
</lang>
 
=={{header|BASIC}}==
{{works with|GW-BASIC}}
 
{{works with|QBasic}}
{{works with|MSX BASIC}}
 
{{works with|ZX Spectrum Basic}}
 
{{works with|Liberty BASIC}}
<syntaxhighlight lang="qbasic">LPRINT "Hello World!"</syntaxhighlight>
 
<lang qbasic>LPRINT "Hello World!"</lang>
 
==={{header|BaCon}}===
Piping data to ''lp'' would also work. This example demonstrates writing to a device.
<langsyntaxhighlight lang="freebasic">' Hello, printer
READ msg$
DATA "Hello World!\n"
Line 143 ⟶ 144:
OPEN "/dev/lp0" FOR DEVICE AS printer
PUTBYTE msg$ TO printer SIZE LEN(msg$)
CLOSE DEVICE printer</langsyntaxhighlight>
 
==={{header|BASIC256}}===
<syntaxhighlight lang="basic256">printeron
font "Arial", 20, 50
text 10,100, "Hello World!"
printeroff</syntaxhighlight>
 
==={{header|BBC BASIC}}===
{{works with|BBC BASIC for Windows}}
<syntaxhighlight lang="bbcbasic"> prn% = OPENOUT("PRN:")
PRINT #prn%, "Hello World!"
CLOSE #prn%</syntaxhighlight>
 
==={{header|GW-BASIC}}===
{{works with|BASICA}}
{{works with|PC-BASIC}}
{{works with|QBasic}}
<syntaxhighlight lang="qbasic">LPRINT "Hello World!"</syntaxhighlight>
 
==={{header|IS-BASIC}}===
<langsyntaxhighlight ISlang="is-BASICbasic">LPRINT "Hello World!"</langsyntaxhighlight>
 
==={{header|BatchMSX FileBasic}}===
<syntaxhighlight lang="qbasic">LPRINT "Hello World!"</syntaxhighlight>
 
==={{header|True BASIC}}===
<lang dos>ECHO Hello world!>PRN</lang>
<syntaxhighlight lang="qbasic">OPEN #1: PRINTER !Open channel #1 for the printer
PRINT #1: "Hello World!"
END</syntaxhighlight>
 
==={{header|BBC BASICYabasic}}===
<syntaxhighlight lang="yabasic">open window 100,100
{{works with|BBC BASIC for Windows}}
open printer
<lang bbcbasic> prn% = OPENOUT("PRN:")
text 10, PRINT #prn%50, "Hello World!"
close printer
CLOSE #prn%</lang>
close window</syntaxhighlight>
 
=={{header|Batch File}}==
<syntaxhighlight lang="dos">ECHO Hello world!>PRN</syntaxhighlight>
 
=={{header|C}}==
===[[Unix]]===
Assuming that the line printer is attached to /dev/lp0
<langsyntaxhighlight Clang="c">#include <stdio.h>
 
int main()
Line 170 ⟶ 197:
fclose(lp);
return 0;
}</langsyntaxhighlight>
 
=={{header|C sharp}}==
Line 177 ⟶ 204:
which is out of scope of this example.
 
<langsyntaxhighlight Clang="c sharp">
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public class DOCINFOA
Line 237 ⟶ 264:
ClosePrinter(hPrinter);
}
}</langsyntaxhighlight>
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">#include <iostream>
#include <fstream>
 
Line 249 ⟶ 276:
lprFile.close();
return 0;
}</langsyntaxhighlight>
 
=={{header|Clipper}}==
<langsyntaxhighlight Clipperlang="clipper">SET PRINT ON
SET CONSOLE OFF
? "Hello World!"
SET PRINT OFF
SET CONSOLE ON
</syntaxhighlight>
</lang>
 
=={{header|Clojure}}==
Translated from Java (mechanically, as I don't understand how to test a line printer):
<langsyntaxhighlight lang="clojure">(ns rosetta-code.line-printer
(:import java.io.FileWriter))
 
(defn -main [& args]
(with-open [wr (new FileWriter "/dev/lp0")]
(.write wr "Hello, World!")))</langsyntaxhighlight>
 
=={{header|COBOL}}==
<langsyntaxhighlight COBOLlang="cobol">IDENTIFICATION DIVISION.
PROGRAM-ID. GOODBYE-WORLD-PRINTER.
 
Line 276 ⟶ 303:
UPON PRINTER
END-DISPLAY.
STOP RUN.</langsyntaxhighlight>
 
=={{header|Commodore BASIC}}==
Most Commodore printer peripherals operate off the IEC bus commonly as device 4 or 5. It is also possible that some printers may be connected through the RS-232 serial port (typically device 2). This example assumes a device on the IEC bus with a default setting of device 4. This example does not utilize any printer control codes to change font, pitch, quality, graphics, etc., as those can vary between brands and models of printer.
 
<syntaxhighlight lang="commodorebasicv2">
<lang CommodoreBASICv2>
10 rem rosetta code - "Hello World" on line printer
20 open 7,4 : rem open <logical file number>, <device number>
30 print#7,"hello world!" : rem print line as shown to logical file number
40 close 7 : rem close the file number
</syntaxhighlight>
</lang>
 
 
=={{header|Common Lisp}}==
Assuming that the line printer is attached to /dev/lp0
<langsyntaxhighlight Lisplang="lisp">(defun main ()
(with-open-file (stream "/dev/lp0"
:direction :output
Line 297 ⟶ 324:
(format stream "Hello World~%")))
(main)
</syntaxhighlight>
</lang>
 
=={{header|D}}==
<langsyntaxhighlight lang="d">import std.stdio;
 
void main()
Line 307 ⟶ 334:
lp.writeln("Hello World!");
}
</syntaxhighlight>
</lang>
 
=={{header|Delphi}}==
<langsyntaxhighlight Delphilang="delphi">program Project1;
 
{$APPTYPE CONSOLE}
Line 323 ⟶ 350:
Writeln(lPrinterAsTextFile, 'Hello World!');
CloseFile(lPrinterAsTextFile);
end.</langsyntaxhighlight>
 
=={{header|Diego}}==
Once the caller has met the computer and its printer...
<syntaxhighlight lang="diego">with_computer(comp1)_printer(lp1)_text(Hello World!);</syntaxhighlight>
If the caller is the computer...
<syntaxhighlight lang="diego">with_printer(lp1)_text(Hello World!);</syntaxhighlight>
 
=={{header|Dragon}}==
<langsyntaxhighlight lang="dragon">
select "files"
 
Line 334 ⟶ 367:
flush(f2)
fclose(f2)
</syntaxhighlight>
</lang>
 
=={{header|EchoLisp}}==
EchoLisp supports a virtual printer which is not stdout. It is actually an extensible division of the HTML document, with printer pages as subdivisions. Printer and pages may be hidden/shown at convenience.
<langsyntaxhighlight lang="lisp">
(printer-font "Courier") ;; change printer font
(printer-page "ROSETTA CODE") ;; starts a new page with nice header
(printer-writeln "Hello World!") ;; prints new line (not seen on stdout)
</syntaxhighlight>
</lang>
 
=={{header|EDSAC order code}}==
This program uses self-modifying code to loop through an array of characters. Since the EDSAC character set does not include lower-case letters or exclamation marks, we actually print <tt>HELLO WORLD</tt> followed by a carriage return and a line feed. Strings cannot be null-terminated, because 0 happens to be the character code for <tt>P</tt>; instead, we mark the final character by including a 1 (which has no printable effect) in the least significant bit.
<langsyntaxhighlight lang="edsac">[ Hello world
===========
 
Line 406 ⟶ 439:
&D [ Line feed + 1 ]
 
EZPF</langsyntaxhighlight>
 
=== Alternative ===
As noted, null in the sense of zero cannot be used as a string terminator on EDSAC. However, it is possible to use the EDSAC null, whose 5-bit code is 10000. The subroutine below demonstrates this.
 
After the string characters, the terminating null is also sent to the teleprinter. This is because the teleprinter had a one-character buffer, so that an O order did not print its own character immediately, but stored it in the buffer and printed the character set up by the previous O order (Wilkes, Wheeler & Gill, 1951 edition, page 50). Sending the terminating null to the teleprinter ensures that the last character of the string is printed at the same time as the rest.
 
The EDSAC PC simulator allows .F for null and *F for letter shift, but it seems from WWG that on the original EDSAC these had to be input as K4096F and K2048F respectively.
<syntaxhighlight lang="edsac">
[Alternative "Hello World" for Rosetta Code]
 
[Subroutine to print a string.]
[Parameter: A order for first character follows subroutine call (G order).]
[Modified 2022-07-13: A order for first character was formerly passed in 0F.]
[String is terminated with EDSAC null, which is printed]
T56K GK [load at 56; set relative addressing]
A18@ U17@ [plant return link, increasing address by 3
instead of 2 as usual]
S19@ [make A order to load A order after subroutine call]
T4@ [plant in code]
[4] AF [(planted) load A order after subroutine call]
[5] T6@ [loop: plant A order for next character]
[6] AF [load next character]
UF [to 0F for printing; keep it in acc]
OF [output to teleprinter]
E12@ [if char >= 0, not EDSAC null]
A20@ [if char < 0, add 15 to test for EDSAC null]
G16@ [jump to exit if null]
[12] TF [clear acc]
A6@ A2F [inc address in A order above]
G5@ [loop back, because top 5 bits = A = 11100]
[16] TF [clear acc on exit (EDSAC convention)]
[17] ZF [(planted) jump back to caller]
[18] U3F [constant for making return link]
[19] U1F [constant for picking up parameter]
[20] K2048F [constant for testing final null]
 
[Main routine]
T96K GK [load at 96; set relative addressing
[Enter with acc = 0]
[0] A@ G56F [call print subroutine]
A4@ [A order for first character of string]
ZF [subroutine returns here; halt machine]
[4] K2048F HF EF LF LF OF !F WF OF RF LF DF @F &F K4096F
[The above string is: letter shift, 'HELLO WORLD', CR, LF, null]
EZ [define entry point]
PF [acc = 0 on entry]
[end]
</syntaxhighlight>
 
=={{header|ERRE}}==
<syntaxhighlight lang="erre">
<lang ERRE>
! Hello World in ERRE language
PROGRAM HELLO
Line 417 ⟶ 498:
!$NOREDIR
END PROGRAM
</syntaxhighlight>
</lang>
 
Prints on LPT1: (if exists) without opening a file.
Line 426 ⟶ 507:
Prints through Unix "lpr" command.
 
<langsyntaxhighlight lang="factor">( scratchpad ) USE: io.encodings.utf8
( scratchpad ) USE: io.launcher
( scratchpad ) "lpr" utf8 [ "Hello World!" print ] with-process-writer</langsyntaxhighlight>
 
=={{header|Forth}}==
Forth systems currently run on everything from bare metal to modern multi-user operating systems and printers are handled differently on each. This demonstration shows a common way that text output is re-directed to printers and/or other devices by vectoring the action of the Forth word EMIT. Emit takes one character off the stack and outputs it to a device. By defining all I/O with the primitive operation EMIT, we can vector the output anywhere we choose, even on hardware with no O/S. Here we show a very basic printer device driver for an embedded system that adds I/O re-direction to the system's Forth language.
<langsyntaxhighlight Forthlang="forth">\ No operating system, embedded device, printer output example
 
defer emit \ deferred words in Forth are a place holder for an
Line 457 ⟶ 538:
\ vector control words
: >console ['] console-emit is EMIT ; \ assign the execution token of console-emit to EMIT
: >printer ['] printer-emit is EMIT ; \ assign the execution token of printer-emit to EMIT</langsyntaxhighlight>
 
Usage Examples:
Line 481 ⟶ 562:
 
Since for a new job, output would commence with the lineprinter already at the top of a new page, an overprint (no carriage advance) thus means writing to the very first line. If however, top-of-page placement was not assured at your installation, then "1HELLO WORLD!" would do.
<langsyntaxhighlight Fortranlang="fortran"> WRITE (6,1)
1 FORMAT ("+HELLO WORLD!")
END </langsyntaxhighlight>
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">' FB 1.05.0 Win64
 
Open Lpt "Lpt:" As #1 '' prints to default printer
Print #1, "Hello World!"
Close #1</langsyntaxhighlight>
 
=={{header|FutureBasic}}==
The legacy lprint statemenet sends a line of text to the printer. The @(col,row) and %(h,v) options specify where on the page the line should be printed (see the print statement); if you don't specify one of these, the line is printed at the current pen position, usually just under the previously-printed line. lprint is inefficient if you are printing many lines to a page because it reroutes the output each time lprint is executed. In such cases, it's better to execute a sequence of print statements, with the entire sequence preceded by a single route _toPrinter statement and followed by a single route _toScreen statement. FB progammers today use much more sophisticated printer functions designed for complex pagination.
<syntaxhighlight lang="futurebasic">
// lprint [@(col,row)|%(h,v)] "Hello,World!"
lprint "Hello,World!"
route _toScreen
close lprint
</syntaxhighlight>
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import (
Line 510 ⟶ 600:
 
fmt.Fprintln(lp0, "Hello World!")
}</langsyntaxhighlight>
 
=={{header|Groovy}}==
<langsyntaxhighlight lang="groovy">new File('/dev/lp0').write('Hello World!\n')
</syntaxhighlight>
</lang>
 
=={{header|GUISS}}==
 
<langsyntaxhighlight lang="guiss">Start,Programs,Accessories,Notepad,Type:Goodbye World[pling],
Menu:File,Print,Button:OK</langsyntaxhighlight>
 
=={{header|Harbour}}==
<langsyntaxhighlight lang="visualfoxpro">SET PRINT ON
SET CONSOLE OFF
? "Hello World!"
SET PRINT OFF
SET CONSOLE ON</langsyntaxhighlight>
 
=={{header|Haskell}}==
<langsyntaxhighlight lang="haskell">import System.Process (ProcessHandle, runCommand)
 
main :: IO ProcessHandle
main = runCommand "echo \"Hello World!\" | lpr"</langsyntaxhighlight>
 
=={{header|Icon}} and {{header|Unicon}}==
Line 538 ⟶ 628:
Works in both languages, provided printer is attached to <tt>/dev/lp0</tt>.
 
<langsyntaxhighlight lang="unicon">procedure main()
write(open("/dev/lp0","w"),"Hello, world!")
end</langsyntaxhighlight>
 
=={{header|Integer BASIC}}==
Line 548 ⟶ 638:
=={{header|J}}==
 
<langsyntaxhighlight lang="j">require'print'
print'Hello world!'</langsyntaxhighlight>
 
=={{header|Java}}==
 
<langsyntaxhighlight lang="java">import java.io.FileWriter;
import java.io.IOException;
Line 566 ⟶ 656:
}
}
}</langsyntaxhighlight>
 
=={{header|JavaScript}}==
{{works with|Node.js}}
<langsyntaxhighlight lang="javascript">// This example runs on Node.js
var fs = require('fs');
// Assuming lp is at /dev/lp0
var lp = fs.openSync('/dev/lp0', 'w');
fs.writeSync(lp, 'Hello, world!\n');
fs.close(lp);</langsyntaxhighlight>
{{works with|Firefox}}
{{works with|Chromium}}
<langsyntaxhighlight lang="javascript">
document.write("Hello World!");
print(); //Opens a dialog.
</syntaxhighlight>
</lang>
 
=={{header|Joy}}==
<syntaxhighlight lang="joy">"/dev/lp" "w" fopen "Hello World!\n" fputchars fclose.</syntaxhighlight>
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">
lineprinter = Sys.iswindows() ? "LPT3" : "/dev/lp0"
lp = open(lineprinter, "w")
write(lp, "Hello world")
</syntaxhighlight>
</lang>
 
=={{header|Kotlin}}==
{{Works with|Ubuntu|14.04}}
<langsyntaxhighlight lang="scala">import java.io.File
 
fun main(args: Array<String>) {
val text = "Hello World!\n"
File("/dev/lp0").writeText(text)
}</langsyntaxhighlight>
 
=={{header|Lasso}}==
 
<langsyntaxhighlight lang="lasso">File_Write: '/dev/lp0', 'Hello world', -FileOverWrite;</langsyntaxhighlight>
 
=={{header|Locomotive Basic}}==
 
<langsyntaxhighlight lang="locobasic">10 PRINT #8, "Hello World!"</langsyntaxhighlight>
 
=={{header|M2000 Interpreter}}==
We can use printer like a page printer
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Printer {
\\ just change the current layer to Print Page
Line 615 ⟶ 708:
Print "Hello World!"
}
</syntaxhighlight>
</lang>
 
Or we can use ANSI output using a file for export in Lpt1
 
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Try ok {
Open "Lpt1" For OutPut As N '' prints to Lpt1 if exist a printer
Line 626 ⟶ 719:
}
If Not Ok Then Print "Can't Print"
</syntaxhighlight>
</lang>
 
If we have a file in current dir we can use a Dos command:
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Dos "Print /d:lpt1 file " +quote$(dir$+"this.txt");
</syntaxhighlight>
</lang>
Using ; at the end of DOS command we have no open terminal
 
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Dos "command" [, sleep time after call] [;]
</syntaxhighlight>
</lang>
 
=={{header|Maple}}==
<langsyntaxhighlight Maplelang="maple">lprint("Hello World!")</langsyntaxhighlight>
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">commandstring = "echo Hello World! | lpr -P Printer01"
Run[commandstring]</langsyntaxhighlight>
 
=={{header|MATLAB}} / {{header|Octave}}==
===[[Unix]]===
Assuming that the line printer is attached to /dev/lp0
<langsyntaxhighlight Matlablang="matlab"> fid = fopen('/dev/lp0');
fprintf(fid,'Hello World!\n');
fclose(fid);</langsyntaxhighlight>
 
=={{header|MIXAL}}==
<syntaxhighlight lang="mixal">
<lang MIXAL>
LPR EQU 18
STRING EQU 2000
Line 665 ⟶ 758:
ALF D!
END START
</syntaxhighlight>
</lang>
 
=={{header|N/t/roff}}==
Line 680 ⟶ 773:
Because /.ROFF/ is a document formatting language, the majority of lines in a typical /.ROFF/ source file is to be textual input. This input is typeset directly onto the output medium. Therefore, the user need not call a procedure to print text to any terminal.
 
<langsyntaxhighlight Nlang="n/t/roff">
Hello World!
</syntaxhighlight>
</lang>
 
=={{header|Nim}}==
Assuming that the line printer is attached to /dev/lp0:
<langsyntaxhighlight lang="nim">var lp = open("/dev/lp0", fmWrite)
lp.writelnwriteLine "Hello World"
lp.close()</langsyntaxhighlight>
 
=={{header|OCaml}}==
Assuming that the line printer is attached to /dev/lp0
<langsyntaxhighlight lang="ocaml">let () =
let oc = open_out "/dev/lp0" in
output_string oc "Hello world!\n";
close_out oc ;;</langsyntaxhighlight>
 
=={{header|Oforth}}==
<langsyntaxhighlight Oforthlang="oforth">File new("/dev/lp0") dup open(File.WRITE) "Hello world\n" << close</langsyntaxhighlight>
 
=={{header|Ol}}==
<langsyntaxhighlight lang="scheme">
(define p (open-output-file "/dev/lp0"))
(when p
(print-to p "Hello world!")
(close-port p))
</syntaxhighlight>
</lang>
 
=={{header|OpenEdge/Progress}}==
<langsyntaxhighlight lang="progress">OUTPUT TO PRINTER.
PUT UNFORMATTED "Hello world!" SKIP.
OUTPUT CLOSE.</langsyntaxhighlight>
 
=={{header|Pascal}}==
Line 717 ⟶ 810:
{{libheader|Printer}}
Example from the FreePascal documentation:
<langsyntaxhighlight lang="pascal">program testprn;
uses printer;
var i: integer;
Line 737 ⟶ 830:
writeln ( 'Done.' )
{$endif}
end.</langsyntaxhighlight>
 
=={{header|Perl}}==
Assuming that the line printer is attached to /dev/lp0
<langsyntaxhighlight lang="perl">open O, ">", "/dev/lp0";
print O "Hello World!\n";
close O;</langsyntaxhighlight>
 
=={{header|Phix}}==
If you have not got something appropriate attached, this will just hang. Other values you can try, on windows: "AUX", "COM1", "COM2", "LPT1"
<!--<langsyntaxhighlight Phixlang="phix">-->
<span style="color: #004080;">integer</span> <span style="color: #000000;">fn</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">open</span><span style="color: #0000FF;">(</span><span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">platform</span><span style="color: #0000FF;">()=</span><span style="color: #000000;">WIN32</span><span style="color: #0000FF;">?</span><span style="color: #008000;">"PRN"</span><span style="color: #0000FF;">:</span><span style="color: #008000;">"/dev/lp0"</span><span style="color: #0000FF;">),</span><span style="color: #008000;">"w"</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">fn</span><span style="color: #0000FF;">=-</span><span style="color: #000000;">1</span> <span style="color: #008080;">then</span>
Line 757 ⟶ 850:
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #0000FF;">{}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">wait_key</span><span style="color: #0000FF;">()</span>
<!--</langsyntaxhighlight>-->
 
=={{header|PHP}}==
<langsyntaxhighlight PHPlang="php"><?php
file_put_contents('/dev/lp0', 'Hello world!');
?></langsyntaxhighlight>
 
<langsyntaxhighlight PHPlang="php"><?php
fclose(STDOUT);
$STDOUT = fopen('/dev/lp0', 'a');
echo 'Hello world!';
?></langsyntaxhighlight>
 
=={{header|Picat}}==
{{works with|Picat}}
<syntaxhighlight lang="picat">
main =>
Printer = open("/dev/lp0", write),
println(Printer, "Hello, world!"),
flush(Printer),
close(Printer).
</syntaxhighlight>
 
=={{header|PicoLisp}}==
<langsyntaxhighlight PicoLisplang="picolisp">(out '(lpr "-P" "Printer01")
(prinl "Hello world") )</langsyntaxhighlight>
 
=={{header|PL/I}}==
<langsyntaxhighlight lang="pli">
hello: procedure options(main);
put skip list('Hello world.');
end hello;</langsyntaxhighlight>
 
=={{header|PostScript}}==
Technically not really correct, as this has to be sent to the printer directly.
It will output Hello world, then, though.
<langsyntaxhighlight lang="postscript"><</PageSize [595 842]>> setpagedevice % set page size to DIN A4
/Courier findfont % use Courier
12 scalefont setfont % 12 pt
28 802 moveto % 1 cm from the top and left edges
(Hello world) show % draw the string</langsyntaxhighlight>
 
=={{header|Prolog}}==
{{works with|SWI Prolog}}
<syntaxhighlight lang="prolog">
:- initialization(main).
 
main :-
open("/dev/lp0", write, Printer),
writeln(Printer, "Hello, world!"),
flush_output(Printer),
close(Printer).
</syntaxhighlight>
 
=={{header|PureBasic}}==
{{libheader|PureLPRINT}}
<langsyntaxhighlight PureBasiclang="purebasic">MyPrinter$ = LPRINT_GetDefaultPrinter()
If LPRINT_OpenPrinter(MyPrinter$)
If LPRINT_StartDoc("Printing a RC-Task")
Line 800 ⟶ 915:
EndIf
LPRINT_ClosePrinter()
EndIf</langsyntaxhighlight>
 
=={{header|Python}}==
Assuming that the line printer is attached to /dev/lp0:
<langsyntaxhighlight lang="python">lp = open("/dev/lp0")
lp.write("Hello World!\n")
lp.close()</langsyntaxhighlight>
 
If the above code gives you the error "IOError: File not open for writing", try:
<langsyntaxhighlight lang="python">lp = open("/dev/lp0","w")
lp.write("Hello World!\n")
lp.close()</langsyntaxhighlight>
 
=={{header|Racket}}==
 
<langsyntaxhighlight lang="racket">
#lang racket
(define (print text)
Line 827 ⟶ 942:
(λ() (displayln text)))))
(print "Hello World!")
</syntaxhighlight>
</lang>
 
=={{header|Raku}}==
(formerly Perl 6)
 
<syntaxhighlight lang="raku" perl6line>my $lp = open '/dev/lp0', :w;
$lp.say: 'Hello World!';
$lp.close;</langsyntaxhighlight>
 
Or using <code>given</code> to avoid having to write the variable name repeatedly:
 
<syntaxhighlight lang="raku" perl6line>given open '/dev/lp0', :w {
.say: 'Hello World!';
.close;
}</langsyntaxhighlight>
 
=={{header|REXX}}==
Line 847 ⟶ 962:
but a shell command could be used.
<br><br>In DOS (or under Windows):
<langsyntaxhighlight lang="rexx">/*REXX program prints a string to the (DOS) line printer via redirection to a printer.*/
$= 'Hello World!' /*define a string to be used for output*/
'@ECHO' $ ">PRN" /*stick a fork in it, we're all done. */</langsyntaxhighlight>
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
lp = fopen("/dev/lp0","w") fputs(lp,"Hello world!") fclose(lp)
</syntaxhighlight>
</lang>
 
=={{header|RPG}}==
{{works with|ILE RPG}}
<syntaxhighlight lang="rpg">
<lang RPG>
Fqsysprt O F 80 printer
C except
Line 864 ⟶ 979:
Oqsysprt E
O 11 'Hello world'
</syntaxhighlight>
</lang>
 
=={{header|RPL}}==
"Hello world!" PR1
 
=={{header|Ruby}}==
Assumes that <code>lpr</code> command reaches printer.
 
<langsyntaxhighlight lang="ruby">open("| lpr", "w") { |f| f.puts "Hello World!" }</langsyntaxhighlight>
 
=={{header|Run BASIC}}==
<langsyntaxhighlight lang="runbasic"> shell$("echo \"Hello World!\" | lpr")</langsyntaxhighlight>
 
=={{header|Rust}}==
===Unix===
<langsyntaxhighlight lang="rust">use std::fs::OpenOptions;
use std::io::Write;
 
Line 882 ⟶ 1,000:
let file = OpenOptions::new().write(true).open("/dev/lp0").unwrap();
file.write(b"Hello, World!").unwrap();
}</langsyntaxhighlight>
 
=={{header|Salmon}}==
Assuming /dev/lp0 accesses the printer:
 
<langsyntaxhighlight Salmonlang="salmon">open_output_text_file("/dev/lp0").print("Hello World!");</langsyntaxhighlight>
 
Assuming lpr is a command that prints to a printer:
<langsyntaxhighlight Salmonlang="salmon">`echo "Hello World!" | lpr`;</langsyntaxhighlight>
 
=={{header|Scala}}==
{{libheader|Scala}}
===All platforms===
<langsyntaxhighlight lang="scala">import java.awt.print.PrinterException
import scala.swing.TextArea
 
Line 909 ⟶ 1,027:
}
println("Document printed.")
}</langsyntaxhighlight>
 
===[[Unix]]===
Assuming device is attached to lp0
<langsyntaxhighlight Scalalang="scala">object LinePrinter extends App {
import java.io.{ FileWriter, IOException }
{
Line 920 ⟶ 1,038:
lp0.close()
}
}</langsyntaxhighlight>
 
=={{header|Scheme}}==
===[[Unix]]===
Assuming device is attached to lp0
<langsyntaxhighlight lang="scheme">(call-with-output-file "/dev/lp0"
  (lambda (printer)
    (write "Hello World!" printer)))</langsyntaxhighlight>
 
=={{header|Seed7}}==
Assuming that the line printer is attached to /dev/lp0:
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
const proc: main is func
Line 940 ⟶ 1,058:
writeln(lp, "Hello world!");
close(lp);
end func;</langsyntaxhighlight>
 
=={{header|Sidef}}==
<langsyntaxhighlight lang="ruby">Sys.open(\var fh, '>', '/dev/lp0') \
&& fh.say("Hello World!") \
&& fh.close</langsyntaxhighlight>
 
=={{header|Simula}}==
{{works with|SIMULA-67}}
<langsyntaxhighlight lang="simula">BEGIN
OUTTEXT("Hello World!");
OUTIMAGE
END</langsyntaxhighlight>
 
=={{header|Slope}}==
<syntaxhighlight>(file-append-to "/dev/lp0" "Hello world!")</syntaxhighlight>
 
=={{header|Smalltalk}}==
{{works with|Smalltalk/X}}
portable (dispatches to one of bellow):
<langsyntaxhighlight lang="smalltalk">s := PrinterStream defaultPrinter new.
s nextPutLine:'Hello, world'.
s close</langsyntaxhighlight>
===[[Unix]]===
<langsyntaxhighlight lang="smalltalk">s := PipeStream writingTo:'lpr'.
s nextPutLine:'Hello, world'.
s close.</langsyntaxhighlight>
alternative:
<langsyntaxhighlight lang="smalltalk">'/dev/lp0' asFilename writingFileDo:[:s |
s nextPutLine:'Hello, world'.
]</langsyntaxhighlight>
===[[Windows]]===
<langsyntaxhighlight lang="smalltalk">s := WinPrinterStream new.
s nextPutLine:'Hello, world'.
s close.</langsyntaxhighlight>
 
=={{header|SNOBOL4}}==
Line 979 ⟶ 1,100:
By default, the variable "input" is associated with standard input, and the variable "output" is associated with standard output.
 
<langsyntaxhighlight SNOBOL4lang="snobol4"> output = "Hello, world."</langsyntaxhighlight>
 
You can associate the variable "print" with lpt1 (the default local printer port) using the output() function:
 
<langsyntaxhighlight SNOBOL4lang="snobol4"> output(.print,25,"lpt1")
print = "Hello, world."</langsyntaxhighlight>
 
=={{header|Swift}}==
<langsyntaxhighlight Swiftlang="swift">import Foundation
 
let out = NSOutputStream(toFileAtPath: "/dev/lp0", append: true)
Line 993 ⟶ 1,114:
out?.open()
out?.write(UnsafePointer<UInt8>(data!.bytes), maxLength: data!.length)
out?.close()</langsyntaxhighlight>
 
=={{header|Tcl}}==
 
===[[Unix]]===
<langsyntaxhighlight lang="tcl">exec lp << "Hello World!"</langsyntaxhighlight>
<langsyntaxhighlight lang="tcl">set f [open |lp w]
puts $f "Hello World!"
close $f</langsyntaxhighlight>
 
===[[Windows]]===
 
<langsyntaxhighlight lang="tcl">set f [open prn w]
puts $f "Hello World!"
close $f</langsyntaxhighlight>
 
=={{header|UNIX Shell}}==
Use ''one'' of the following lines.
 
<langsyntaxhighlight lang="bash"># Use the default printer queue, with lp(1) or lpr(1).
# 1. The system must have a printer queue.
# 2. The printer queue must understand plain text.
Line 1,032 ⟶ 1,153:
echo 'Hello World!' >/dev/lp0
echo 'Hello World!' >/dev/lpt0
echo 'Hello World!' >/dev/ulpt0</langsyntaxhighlight>
 
=={{header|Wisp}}==
===[[Unix]]===
Assuming that the device is attached to lp0
<langsyntaxhighlight lang="wisp">call-with-output-file "/dev/lp0"
λ : printer
write "Hello World!" printer</langsyntaxhighlight>
 
=={{header|Wren}}==
It is not currently possible to communicate with the printer using Wren-cli. So we need to write a minimal embedded program (no error checking) so the C host can do this for us.
<langsyntaxhighlight ecmascriptlang="wren">/* hello_world_line_printerHello_world_Line_printer.wren */
 
class C {
Line 1,049 ⟶ 1,170:
}
 
C.lprint("Hello World!")</langsyntaxhighlight>
<br>
We now embed this in the following C program, compile and run it.
<langsyntaxhighlight lang="c">/* gcc hello_world_line_printerHello_world_Line_printer.c -o hello_world_line_printerHello_world_Line_printer -lwren -lm */
 
#include <stdio.h>
Line 1,107 ⟶ 1,228:
WrenVM* vm = wrenNewVM(&config);
const char* module = "main";
const char* fileName = "hello_world_line_printerHello_world_Line_printer.wren";
char *script = readFile(fileName);
WrenInterpretResult result = wrenInterpret(vm, module, script);
Line 1,113 ⟶ 1,234:
free(script);
return 0;
}</langsyntaxhighlight>
 
=={{header|X86 Assembly}}==
<langsyntaxhighlight lang="asm">;Assemble with: tasm, tlink /t
;assume direction bit is clear (so si increments)
.model tiny
Line 1,133 ⟶ 1,254:
 
msg db "Hello World!", 0ch, 0 ;0ch = form feed (for laser printer)
end start</langsyntaxhighlight>
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">code Text=12;
Text(2, "Hello World!
");</langsyntaxhighlight>
 
The 2 directs the output to the printer (LPT1).
9,477

edits