Hello world/Line printer: Difference between revisions
Content added Content deleted
m (Small change to code in alternative EDSAC version) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 21: | Line 21: | ||
{{trans|Python}} |
{{trans|Python}} |
||
< |
<syntaxhighlight lang="11l">V lp = File(‘/dev/lp0’, ‘w’) |
||
lp.write("Hello World!\n") |
lp.write("Hello World!\n") |
||
lp.close()</ |
lp.close()</syntaxhighlight> |
||
=={{header|360 Assembly}}== |
=={{header|360 Assembly}}== |
||
< |
<syntaxhighlight lang="360asm">HELLO CSECT |
||
PRINT NOGEN |
PRINT NOGEN |
||
BALR 12,0 |
BALR 12,0 |
||
Line 38: | Line 38: | ||
L1 DS 0CL133 |
L1 DS 0CL133 |
||
HW DC C'Hello World!' |
HW DC C'Hello World!' |
||
END HELLO</ |
END HELLO</syntaxhighlight> |
||
=={{header|Action!}}== |
=={{header|Action!}}== |
||
< |
<syntaxhighlight lang="action!">Proc Main() |
||
Open(1,"P:",8,0) |
Open(1,"P:",8,0) |
||
PrintDE(1,"HELLO WORLD!") |
PrintDE(1,"HELLO WORLD!") |
||
Close(1) |
Close(1) |
||
Return |
Return |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Ada}}== |
=={{header|Ada}}== |
||
===[[Unix]]=== |
===[[Unix]]=== |
||
Assuming that the line printer is attached to /dev/lp0 |
Assuming that the line printer is attached to /dev/lp0 |
||
<syntaxhighlight lang="ada"> |
|||
<lang Ada> |
|||
with Ada.Text_IO; use Ada.Text_IO; |
with Ada.Text_IO; use Ada.Text_IO; |
||
Line 69: | Line 69: | ||
Close (Printer); |
Close (Printer); |
||
end Print_Line; |
end Print_Line; |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|ALGOL 68}}== |
=={{header|ALGOL 68}}== |
||
Line 77: | Line 77: | ||
remote printer interfaced via CUPS. Extending it to other |
remote printer interfaced via CUPS. Extending it to other |
||
environments is left as an exercise for the reader. |
environments is left as an exercise for the reader. |
||
< |
<syntaxhighlight lang="algol68"> |
||
BEGIN |
BEGIN |
||
STRING printer name = "/dev/lp0"; |
STRING printer name = "/dev/lp0"; |
||
Line 97: | Line 97: | ||
FI |
FI |
||
END |
END |
||
</ |
</syntaxhighlight> {{out}} |
||
<pre> |
<pre> |
||
Can't contact line printer on /dev/lp0 |
Can't contact line printer on /dev/lp0 |
||
Line 107: | Line 107: | ||
Assumes a printer card is installed in the Apple II's number 1 expansion slot. |
Assumes a printer card is installed in the Apple II's number 1 expansion slot. |
||
< |
<syntaxhighlight lang="basic"> |
||
PR#1 |
PR#1 |
||
PRINT "HELLO WORLD!" |
PRINT "HELLO WORLD!" |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |
||
<syntaxhighlight lang="autohotkey"> |
|||
<lang AutoHotkey> |
|||
Fileappend, Hello World!, print.txt |
Fileappend, Hello World!, print.txt |
||
Run, print "print.txt" |
Run, print "print.txt" |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|AWK}}== |
=={{header|AWK}}== |
||
Unix / Linux: |
Unix / Linux: |
||
<syntaxhighlight lang="awk"> |
|||
<lang AWK> |
|||
BEGIN { print("Hello World!") >"/dev/lp0" } |
BEGIN { print("Hello World!") >"/dev/lp0" } |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|BASIC}}== |
=={{header|BASIC}}== |
||
Line 128: | Line 128: | ||
{{works with|ZX Spectrum Basic}} |
{{works with|ZX Spectrum Basic}} |
||
{{works with|Liberty BASIC}} |
{{works with|Liberty BASIC}} |
||
< |
<syntaxhighlight lang="qbasic">LPRINT "Hello World!"</syntaxhighlight> |
||
==={{header|BaCon}}=== |
==={{header|BaCon}}=== |
||
Piping data to ''lp'' would also work. This example demonstrates writing to a device. |
Piping data to ''lp'' would also work. This example demonstrates writing to a device. |
||
< |
<syntaxhighlight lang="freebasic">' Hello, printer |
||
READ msg$ |
READ msg$ |
||
DATA "Hello World!\n" |
DATA "Hello World!\n" |
||
Line 139: | Line 139: | ||
OPEN "/dev/lp0" FOR DEVICE AS printer |
OPEN "/dev/lp0" FOR DEVICE AS printer |
||
PUTBYTE msg$ TO printer SIZE LEN(msg$) |
PUTBYTE msg$ TO printer SIZE LEN(msg$) |
||
CLOSE DEVICE printer</ |
CLOSE DEVICE printer</syntaxhighlight> |
||
==={{header|BASIC256}}=== |
==={{header|BASIC256}}=== |
||
< |
<syntaxhighlight lang="basic256">printeron |
||
font "Arial", 20, 50 |
font "Arial", 20, 50 |
||
text 10,100, "Hello World!" |
text 10,100, "Hello World!" |
||
printeroff</ |
printeroff</syntaxhighlight> |
||
==={{header|BBC BASIC}}=== |
==={{header|BBC BASIC}}=== |
||
{{works with|BBC BASIC for Windows}} |
{{works with|BBC BASIC for Windows}} |
||
< |
<syntaxhighlight lang="bbcbasic"> prn% = OPENOUT("PRN:") |
||
PRINT #prn%, "Hello World!" |
PRINT #prn%, "Hello World!" |
||
CLOSE #prn%</ |
CLOSE #prn%</syntaxhighlight> |
||
==={{header|IS-BASIC}}=== |
==={{header|IS-BASIC}}=== |
||
< |
<syntaxhighlight lang="is-basic">LPRINT "Hello World!"</syntaxhighlight> |
||
==={{header|Yabasic}}=== |
==={{header|Yabasic}}=== |
||
< |
<syntaxhighlight lang="yabasic">open window 100,100 |
||
open printer |
open printer |
||
text 10, 50, "Hello World!" |
text 10, 50, "Hello World!" |
||
close printer |
close printer |
||
close window</ |
close window</syntaxhighlight> |
||
=={{header|Batch File}}== |
=={{header|Batch File}}== |
||
<lang |
<syntaxhighlight lang="dos">ECHO Hello world!>PRN</syntaxhighlight> |
||
=={{header|C}}== |
=={{header|C}}== |
||
===[[Unix]]=== |
===[[Unix]]=== |
||
Assuming that the line printer is attached to /dev/lp0 |
Assuming that the line printer is attached to /dev/lp0 |
||
< |
<syntaxhighlight lang="c">#include <stdio.h> |
||
int main() |
int main() |
||
Line 178: | Line 178: | ||
fclose(lp); |
fclose(lp); |
||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
=={{header|C sharp}}== |
=={{header|C sharp}}== |
||
Line 185: | Line 185: | ||
which is out of scope of this example. |
which is out of scope of this example. |
||
< |
<syntaxhighlight lang="c sharp"> |
||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] |
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] |
||
public class DOCINFOA |
public class DOCINFOA |
||
Line 245: | Line 245: | ||
ClosePrinter(hPrinter); |
ClosePrinter(hPrinter); |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|C++}}== |
=={{header|C++}}== |
||
< |
<syntaxhighlight lang="cpp">#include <iostream> |
||
#include <fstream> |
#include <fstream> |
||
Line 257: | Line 257: | ||
lprFile.close(); |
lprFile.close(); |
||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Clipper}}== |
=={{header|Clipper}}== |
||
< |
<syntaxhighlight lang="clipper">SET PRINT ON |
||
SET CONSOLE OFF |
SET CONSOLE OFF |
||
? "Hello World!" |
? "Hello World!" |
||
SET PRINT OFF |
SET PRINT OFF |
||
SET CONSOLE ON |
SET CONSOLE ON |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Clojure}}== |
=={{header|Clojure}}== |
||
Translated from Java (mechanically, as I don't understand how to test a line printer): |
Translated from Java (mechanically, as I don't understand how to test a line printer): |
||
< |
<syntaxhighlight lang="clojure">(ns rosetta-code.line-printer |
||
(:import java.io.FileWriter)) |
(:import java.io.FileWriter)) |
||
(defn -main [& args] |
(defn -main [& args] |
||
(with-open [wr (new FileWriter "/dev/lp0")] |
(with-open [wr (new FileWriter "/dev/lp0")] |
||
(.write wr "Hello, World!")))</ |
(.write wr "Hello, World!")))</syntaxhighlight> |
||
=={{header|COBOL}}== |
=={{header|COBOL}}== |
||
< |
<syntaxhighlight lang="cobol">IDENTIFICATION DIVISION. |
||
PROGRAM-ID. GOODBYE-WORLD-PRINTER. |
PROGRAM-ID. GOODBYE-WORLD-PRINTER. |
||
Line 284: | Line 284: | ||
UPON PRINTER |
UPON PRINTER |
||
END-DISPLAY. |
END-DISPLAY. |
||
STOP RUN.</ |
STOP RUN.</syntaxhighlight> |
||
=={{header|Commodore BASIC}}== |
=={{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. |
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 |
10 rem rosetta code - "Hello World" on line printer |
||
20 open 7,4 : rem open <logical file number>, <device number> |
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 |
30 print#7,"hello world!" : rem print line as shown to logical file number |
||
40 close 7 : rem close the file number |
40 close 7 : rem close the file number |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Common Lisp}}== |
=={{header|Common Lisp}}== |
||
Assuming that the line printer is attached to /dev/lp0 |
Assuming that the line printer is attached to /dev/lp0 |
||
< |
<syntaxhighlight lang="lisp">(defun main () |
||
(with-open-file (stream "/dev/lp0" |
(with-open-file (stream "/dev/lp0" |
||
:direction :output |
:direction :output |
||
Line 305: | Line 305: | ||
(format stream "Hello World~%"))) |
(format stream "Hello World~%"))) |
||
(main) |
(main) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|D}}== |
=={{header|D}}== |
||
< |
<syntaxhighlight lang="d">import std.stdio; |
||
void main() |
void main() |
||
Line 315: | Line 315: | ||
lp.writeln("Hello World!"); |
lp.writeln("Hello World!"); |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Delphi}}== |
=={{header|Delphi}}== |
||
< |
<syntaxhighlight lang="delphi">program Project1; |
||
{$APPTYPE CONSOLE} |
{$APPTYPE CONSOLE} |
||
Line 331: | Line 331: | ||
Writeln(lPrinterAsTextFile, 'Hello World!'); |
Writeln(lPrinterAsTextFile, 'Hello World!'); |
||
CloseFile(lPrinterAsTextFile); |
CloseFile(lPrinterAsTextFile); |
||
end.</ |
end.</syntaxhighlight> |
||
=={{header|Diego}}== |
=={{header|Diego}}== |
||
Once the caller has met the computer and its printer... |
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... |
If the caller is the computer... |
||
< |
<syntaxhighlight lang="diego">with_printer(lp1)_text(Hello World!);</syntaxhighlight> |
||
=={{header|Dragon}}== |
=={{header|Dragon}}== |
||
< |
<syntaxhighlight lang="dragon"> |
||
select "files" |
select "files" |
||
Line 348: | Line 348: | ||
flush(f2) |
flush(f2) |
||
fclose(f2) |
fclose(f2) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|EchoLisp}}== |
=={{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. |
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. |
||
< |
<syntaxhighlight lang="lisp"> |
||
(printer-font "Courier") ;; change printer font |
(printer-font "Courier") ;; change printer font |
||
(printer-page "ROSETTA CODE") ;; starts a new page with nice header |
(printer-page "ROSETTA CODE") ;; starts a new page with nice header |
||
(printer-writeln "Hello World!") ;; prints new line (not seen on stdout) |
(printer-writeln "Hello World!") ;; prints new line (not seen on stdout) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|EDSAC order code}}== |
=={{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. |
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. |
||
< |
<syntaxhighlight lang="edsac">[ Hello world |
||
=========== |
=========== |
||
Line 420: | Line 420: | ||
&D [ Line feed + 1 ] |
&D [ Line feed + 1 ] |
||
EZPF</ |
EZPF</syntaxhighlight> |
||
==={{header|Alternative}}=== |
==={{header|Alternative}}=== |
||
Line 428: | Line 428: | ||
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. |
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] |
[Alternative "Hello World" for Rosetta Code] |
||
Line 468: | Line 468: | ||
PF [acc = 0 on entry] |
PF [acc = 0 on entry] |
||
[end] |
[end] |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|ERRE}}== |
=={{header|ERRE}}== |
||
<syntaxhighlight lang="erre"> |
|||
<lang ERRE> |
|||
! Hello World in ERRE language |
! Hello World in ERRE language |
||
PROGRAM HELLO |
PROGRAM HELLO |
||
Line 479: | Line 479: | ||
!$NOREDIR |
!$NOREDIR |
||
END PROGRAM |
END PROGRAM |
||
</syntaxhighlight> |
|||
</lang> |
|||
Prints on LPT1: (if exists) without opening a file. |
Prints on LPT1: (if exists) without opening a file. |
||
Line 488: | Line 488: | ||
Prints through Unix "lpr" command. |
Prints through Unix "lpr" command. |
||
< |
<syntaxhighlight lang="factor">( scratchpad ) USE: io.encodings.utf8 |
||
( scratchpad ) USE: io.launcher |
( scratchpad ) USE: io.launcher |
||
( scratchpad ) "lpr" utf8 [ "Hello World!" print ] with-process-writer</ |
( scratchpad ) "lpr" utf8 [ "Hello World!" print ] with-process-writer</syntaxhighlight> |
||
=={{header|Forth}}== |
=={{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. |
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. |
||
< |
<syntaxhighlight lang="forth">\ No operating system, embedded device, printer output example |
||
defer emit \ deferred words in Forth are a place holder for an |
defer emit \ deferred words in Forth are a place holder for an |
||
Line 519: | Line 519: | ||
\ vector control words |
\ vector control words |
||
: >console ['] console-emit is EMIT ; \ assign the execution token of console-emit to EMIT |
: >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</ |
: >printer ['] printer-emit is EMIT ; \ assign the execution token of printer-emit to EMIT</syntaxhighlight> |
||
Usage Examples: |
Usage Examples: |
||
Line 543: | Line 543: | ||
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. |
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. |
||
< |
<syntaxhighlight lang="fortran"> WRITE (6,1) |
||
1 FORMAT ("+HELLO WORLD!") |
1 FORMAT ("+HELLO WORLD!") |
||
END </ |
END </syntaxhighlight> |
||
=={{header|FreeBASIC}}== |
=={{header|FreeBASIC}}== |
||
< |
<syntaxhighlight lang="freebasic">' FB 1.05.0 Win64 |
||
Open Lpt "Lpt:" As #1 '' prints to default printer |
Open Lpt "Lpt:" As #1 '' prints to default printer |
||
Print #1, "Hello World!" |
Print #1, "Hello World!" |
||
Close #1</ |
Close #1</syntaxhighlight> |
||
=={{header|Go}}== |
=={{header|Go}}== |
||
< |
<syntaxhighlight lang="go">package main |
||
import ( |
import ( |
||
Line 572: | Line 572: | ||
fmt.Fprintln(lp0, "Hello World!") |
fmt.Fprintln(lp0, "Hello World!") |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Groovy}}== |
=={{header|Groovy}}== |
||
< |
<syntaxhighlight lang="groovy">new File('/dev/lp0').write('Hello World!\n') |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|GUISS}}== |
=={{header|GUISS}}== |
||
< |
<syntaxhighlight lang="guiss">Start,Programs,Accessories,Notepad,Type:Goodbye World[pling], |
||
Menu:File,Print,Button:OK</ |
Menu:File,Print,Button:OK</syntaxhighlight> |
||
=={{header|Harbour}}== |
=={{header|Harbour}}== |
||
< |
<syntaxhighlight lang="visualfoxpro">SET PRINT ON |
||
SET CONSOLE OFF |
SET CONSOLE OFF |
||
? "Hello World!" |
? "Hello World!" |
||
SET PRINT OFF |
SET PRINT OFF |
||
SET CONSOLE ON</ |
SET CONSOLE ON</syntaxhighlight> |
||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
< |
<syntaxhighlight lang="haskell">import System.Process (ProcessHandle, runCommand) |
||
main :: IO ProcessHandle |
main :: IO ProcessHandle |
||
main = runCommand "echo \"Hello World!\" | lpr"</ |
main = runCommand "echo \"Hello World!\" | lpr"</syntaxhighlight> |
||
=={{header|Icon}} and {{header|Unicon}}== |
=={{header|Icon}} and {{header|Unicon}}== |
||
Line 600: | Line 600: | ||
Works in both languages, provided printer is attached to <tt>/dev/lp0</tt>. |
Works in both languages, provided printer is attached to <tt>/dev/lp0</tt>. |
||
< |
<syntaxhighlight lang="unicon">procedure main() |
||
write(open("/dev/lp0","w"),"Hello, world!") |
write(open("/dev/lp0","w"),"Hello, world!") |
||
end</ |
end</syntaxhighlight> |
||
=={{header|Integer BASIC}}== |
=={{header|Integer BASIC}}== |
||
Line 610: | Line 610: | ||
=={{header|J}}== |
=={{header|J}}== |
||
< |
<syntaxhighlight lang="j">require'print' |
||
print'Hello world!'</ |
print'Hello world!'</syntaxhighlight> |
||
=={{header|Java}}== |
=={{header|Java}}== |
||
< |
<syntaxhighlight lang="java">import java.io.FileWriter; |
||
import java.io.IOException; |
import java.io.IOException; |
||
Line 628: | Line 628: | ||
} |
} |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|JavaScript}}== |
=={{header|JavaScript}}== |
||
{{works with|Node.js}} |
{{works with|Node.js}} |
||
< |
<syntaxhighlight lang="javascript">// This example runs on Node.js |
||
var fs = require('fs'); |
var fs = require('fs'); |
||
// Assuming lp is at /dev/lp0 |
// Assuming lp is at /dev/lp0 |
||
var lp = fs.openSync('/dev/lp0', 'w'); |
var lp = fs.openSync('/dev/lp0', 'w'); |
||
fs.writeSync(lp, 'Hello, world!\n'); |
fs.writeSync(lp, 'Hello, world!\n'); |
||
fs.close(lp);</ |
fs.close(lp);</syntaxhighlight> |
||
{{works with|Firefox}} |
{{works with|Firefox}} |
||
{{works with|Chromium}} |
{{works with|Chromium}} |
||
< |
<syntaxhighlight lang="javascript"> |
||
document.write("Hello World!"); |
document.write("Hello World!"); |
||
print(); //Opens a dialog. |
print(); //Opens a dialog. |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
< |
<syntaxhighlight lang="julia"> |
||
lineprinter = Sys.iswindows() ? "LPT3" : "/dev/lp0" |
lineprinter = Sys.iswindows() ? "LPT3" : "/dev/lp0" |
||
lp = open(lineprinter, "w") |
lp = open(lineprinter, "w") |
||
write(lp, "Hello world") |
write(lp, "Hello world") |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |
||
{{Works with|Ubuntu|14.04}} |
{{Works with|Ubuntu|14.04}} |
||
< |
<syntaxhighlight lang="scala">import java.io.File |
||
fun main(args: Array<String>) { |
fun main(args: Array<String>) { |
||
val text = "Hello World!\n" |
val text = "Hello World!\n" |
||
File("/dev/lp0").writeText(text) |
File("/dev/lp0").writeText(text) |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Lasso}}== |
=={{header|Lasso}}== |
||
< |
<syntaxhighlight lang="lasso">File_Write: '/dev/lp0', 'Hello world', -FileOverWrite;</syntaxhighlight> |
||
=={{header|Locomotive Basic}}== |
=={{header|Locomotive Basic}}== |
||
< |
<syntaxhighlight lang="locobasic">10 PRINT #8, "Hello World!"</syntaxhighlight> |
||
=={{header|M2000 Interpreter}}== |
=={{header|M2000 Interpreter}}== |
||
We can use printer like a page printer |
We can use printer like a page printer |
||
<syntaxhighlight lang="m2000 interpreter"> |
|||
<lang M2000 Interpreter> |
|||
Printer { |
Printer { |
||
\\ just change the current layer to Print Page |
\\ just change the current layer to Print Page |
||
Line 677: | Line 677: | ||
Print "Hello World!" |
Print "Hello World!" |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
Or we can use ANSI output using a file for export in Lpt1 |
Or we can use ANSI output using a file for export in Lpt1 |
||
<syntaxhighlight lang="m2000 interpreter"> |
|||
<lang M2000 Interpreter> |
|||
Try ok { |
Try ok { |
||
Open "Lpt1" For OutPut As N '' prints to Lpt1 if exist a printer |
Open "Lpt1" For OutPut As N '' prints to Lpt1 if exist a printer |
||
Line 688: | Line 688: | ||
} |
} |
||
If Not Ok Then Print "Can't Print" |
If Not Ok Then Print "Can't Print" |
||
</syntaxhighlight> |
|||
</lang> |
|||
If we have a file in current dir we can use a Dos command: |
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"); |
Dos "Print /d:lpt1 file " +quote$(dir$+"this.txt"); |
||
</syntaxhighlight> |
|||
</lang> |
|||
Using ; at the end of DOS command we have no open terminal |
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] [;] |
Dos "command" [, sleep time after call] [;] |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Maple}}== |
=={{header|Maple}}== |
||
< |
<syntaxhighlight lang="maple">lprint("Hello World!")</syntaxhighlight> |
||
=={{header|Mathematica}} / {{header|Wolfram Language}}== |
=={{header|Mathematica}} / {{header|Wolfram Language}}== |
||
< |
<syntaxhighlight lang="mathematica">commandstring = "echo Hello World! | lpr -P Printer01" |
||
Run[commandstring]</ |
Run[commandstring]</syntaxhighlight> |
||
=={{header|MATLAB}} / {{header|Octave}}== |
=={{header|MATLAB}} / {{header|Octave}}== |
||
===[[Unix]]=== |
===[[Unix]]=== |
||
Assuming that the line printer is attached to /dev/lp0 |
Assuming that the line printer is attached to /dev/lp0 |
||
< |
<syntaxhighlight lang="matlab"> fid = fopen('/dev/lp0'); |
||
fprintf(fid,'Hello World!\n'); |
fprintf(fid,'Hello World!\n'); |
||
fclose(fid);</ |
fclose(fid);</syntaxhighlight> |
||
=={{header|MIXAL}}== |
=={{header|MIXAL}}== |
||
<syntaxhighlight lang="mixal"> |
|||
<lang MIXAL> |
|||
LPR EQU 18 |
LPR EQU 18 |
||
STRING EQU 2000 |
STRING EQU 2000 |
||
Line 727: | Line 727: | ||
ALF D! |
ALF D! |
||
END START |
END START |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|N/t/roff}}== |
=={{header|N/t/roff}}== |
||
Line 742: | Line 742: | ||
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. |
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. |
||
< |
<syntaxhighlight lang="n/t/roff"> |
||
Hello World! |
Hello World! |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
Assuming that the line printer is attached to /dev/lp0: |
Assuming that the line printer is attached to /dev/lp0: |
||
< |
<syntaxhighlight lang="nim">var lp = open("/dev/lp0", fmWrite) |
||
lp.writeln "Hello World" |
lp.writeln "Hello World" |
||
lp.close()</ |
lp.close()</syntaxhighlight> |
||
=={{header|OCaml}}== |
=={{header|OCaml}}== |
||
Assuming that the line printer is attached to /dev/lp0 |
Assuming that the line printer is attached to /dev/lp0 |
||
< |
<syntaxhighlight lang="ocaml">let () = |
||
let oc = open_out "/dev/lp0" in |
let oc = open_out "/dev/lp0" in |
||
output_string oc "Hello world!\n"; |
output_string oc "Hello world!\n"; |
||
close_out oc ;;</ |
close_out oc ;;</syntaxhighlight> |
||
=={{header|Oforth}}== |
=={{header|Oforth}}== |
||
< |
<syntaxhighlight lang="oforth">File new("/dev/lp0") dup open(File.WRITE) "Hello world\n" << close</syntaxhighlight> |
||
=={{header|Ol}}== |
=={{header|Ol}}== |
||
< |
<syntaxhighlight lang="scheme"> |
||
(define p (open-output-file "/dev/lp0")) |
(define p (open-output-file "/dev/lp0")) |
||
(when p |
(when p |
||
(print-to p "Hello world!") |
(print-to p "Hello world!") |
||
(close-port p)) |
(close-port p)) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|OpenEdge/Progress}}== |
=={{header|OpenEdge/Progress}}== |
||
< |
<syntaxhighlight lang="progress">OUTPUT TO PRINTER. |
||
PUT UNFORMATTED "Hello world!" SKIP. |
PUT UNFORMATTED "Hello world!" SKIP. |
||
OUTPUT CLOSE.</ |
OUTPUT CLOSE.</syntaxhighlight> |
||
=={{header|Pascal}}== |
=={{header|Pascal}}== |
||
Line 779: | Line 779: | ||
{{libheader|Printer}} |
{{libheader|Printer}} |
||
Example from the FreePascal documentation: |
Example from the FreePascal documentation: |
||
< |
<syntaxhighlight lang="pascal">program testprn; |
||
uses printer; |
uses printer; |
||
var i: integer; |
var i: integer; |
||
Line 799: | Line 799: | ||
writeln ( 'Done.' ) |
writeln ( 'Done.' ) |
||
{$endif} |
{$endif} |
||
end.</ |
end.</syntaxhighlight> |
||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
Assuming that the line printer is attached to /dev/lp0 |
Assuming that the line printer is attached to /dev/lp0 |
||
< |
<syntaxhighlight lang="perl">open O, ">", "/dev/lp0"; |
||
print O "Hello World!\n"; |
print O "Hello World!\n"; |
||
close O;</ |
close O;</syntaxhighlight> |
||
=={{header|Phix}}== |
=={{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" |
If you have not got something appropriate attached, this will just hang. Other values you can try, on windows: "AUX", "COM1", "COM2", "LPT1" |
||
<!--< |
<!--<syntaxhighlight lang="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: #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> |
<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 819: | Line 819: | ||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span> |
<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> |
<span style="color: #0000FF;">{}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">wait_key</span><span style="color: #0000FF;">()</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
=={{header|PHP}}== |
=={{header|PHP}}== |
||
< |
<syntaxhighlight lang="php"><?php |
||
file_put_contents('/dev/lp0', 'Hello world!'); |
file_put_contents('/dev/lp0', 'Hello world!'); |
||
?></ |
?></syntaxhighlight> |
||
< |
<syntaxhighlight lang="php"><?php |
||
fclose(STDOUT); |
fclose(STDOUT); |
||
$STDOUT = fopen('/dev/lp0', 'a'); |
$STDOUT = fopen('/dev/lp0', 'a'); |
||
echo 'Hello world!'; |
echo 'Hello world!'; |
||
?></ |
?></syntaxhighlight> |
||
=={{header|Picat}}== |
=={{header|Picat}}== |
||
{{works with|Picat}} |
{{works with|Picat}} |
||
<syntaxhighlight lang="picat"> |
|||
<lang Picat> |
|||
main => |
main => |
||
Printer = open("/dev/lp0", write), |
Printer = open("/dev/lp0", write), |
||
Line 840: | Line 840: | ||
flush(Printer), |
flush(Printer), |
||
close(Printer). |
close(Printer). |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |
||
< |
<syntaxhighlight lang="picolisp">(out '(lpr "-P" "Printer01") |
||
(prinl "Hello world") )</ |
(prinl "Hello world") )</syntaxhighlight> |
||
=={{header|PL/I}}== |
=={{header|PL/I}}== |
||
< |
<syntaxhighlight lang="pli"> |
||
hello: procedure options(main); |
hello: procedure options(main); |
||
put skip list('Hello world.'); |
put skip list('Hello world.'); |
||
end hello;</ |
end hello;</syntaxhighlight> |
||
=={{header|PostScript}}== |
=={{header|PostScript}}== |
||
Technically not really correct, as this has to be sent to the printer directly. |
Technically not really correct, as this has to be sent to the printer directly. |
||
It will output Hello world, then, though. |
It will output Hello world, then, though. |
||
< |
<syntaxhighlight lang="postscript"><</PageSize [595 842]>> setpagedevice % set page size to DIN A4 |
||
/Courier findfont % use Courier |
/Courier findfont % use Courier |
||
12 scalefont setfont % 12 pt |
12 scalefont setfont % 12 pt |
||
28 802 moveto % 1 cm from the top and left edges |
28 802 moveto % 1 cm from the top and left edges |
||
(Hello world) show % draw the string</ |
(Hello world) show % draw the string</syntaxhighlight> |
||
=={{header|Prolog}}== |
=={{header|Prolog}}== |
||
{{works with|SWI Prolog}} |
{{works with|SWI Prolog}} |
||
<syntaxhighlight lang="prolog"> |
|||
<lang Prolog> |
|||
:- initialization(main). |
:- initialization(main). |
||
Line 871: | Line 871: | ||
flush_output(Printer), |
flush_output(Printer), |
||
close(Printer). |
close(Printer). |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|PureBasic}}== |
=={{header|PureBasic}}== |
||
{{libheader|PureLPRINT}} |
{{libheader|PureLPRINT}} |
||
< |
<syntaxhighlight lang="purebasic">MyPrinter$ = LPRINT_GetDefaultPrinter() |
||
If LPRINT_OpenPrinter(MyPrinter$) |
If LPRINT_OpenPrinter(MyPrinter$) |
||
If LPRINT_StartDoc("Printing a RC-Task") |
If LPRINT_StartDoc("Printing a RC-Task") |
||
Line 884: | Line 884: | ||
EndIf |
EndIf |
||
LPRINT_ClosePrinter() |
LPRINT_ClosePrinter() |
||
EndIf</ |
EndIf</syntaxhighlight> |
||
=={{header|Python}}== |
=={{header|Python}}== |
||
Assuming that the line printer is attached to /dev/lp0: |
Assuming that the line printer is attached to /dev/lp0: |
||
< |
<syntaxhighlight lang="python">lp = open("/dev/lp0") |
||
lp.write("Hello World!\n") |
lp.write("Hello World!\n") |
||
lp.close()</ |
lp.close()</syntaxhighlight> |
||
If the above code gives you the error "IOError: File not open for writing", try: |
If the above code gives you the error "IOError: File not open for writing", try: |
||
< |
<syntaxhighlight lang="python">lp = open("/dev/lp0","w") |
||
lp.write("Hello World!\n") |
lp.write("Hello World!\n") |
||
lp.close()</ |
lp.close()</syntaxhighlight> |
||
=={{header|Racket}}== |
=={{header|Racket}}== |
||
< |
<syntaxhighlight lang="racket"> |
||
#lang racket |
#lang racket |
||
(define (print text) |
(define (print text) |
||
Line 911: | Line 911: | ||
(λ() (displayln text))))) |
(λ() (displayln text))))) |
||
(print "Hello World!") |
(print "Hello World!") |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
(formerly Perl 6) |
(formerly Perl 6) |
||
<lang |
<syntaxhighlight lang="raku" line>my $lp = open '/dev/lp0', :w; |
||
$lp.say: 'Hello World!'; |
$lp.say: 'Hello World!'; |
||
$lp.close;</ |
$lp.close;</syntaxhighlight> |
||
Or using <code>given</code> to avoid having to write the variable name repeatedly: |
Or using <code>given</code> to avoid having to write the variable name repeatedly: |
||
<lang |
<syntaxhighlight lang="raku" line>given open '/dev/lp0', :w { |
||
.say: 'Hello World!'; |
.say: 'Hello World!'; |
||
.close; |
.close; |
||
}</ |
}</syntaxhighlight> |
||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
Line 931: | Line 931: | ||
but a shell command could be used. |
but a shell command could be used. |
||
<br><br>In DOS (or under Windows): |
<br><br>In DOS (or under Windows): |
||
< |
<syntaxhighlight 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*/ |
$= 'Hello World!' /*define a string to be used for output*/ |
||
'@ECHO' $ ">PRN" /*stick a fork in it, we're all done. */</ |
'@ECHO' $ ">PRN" /*stick a fork in it, we're all done. */</syntaxhighlight> |
||
=={{header|Ring}}== |
=={{header|Ring}}== |
||
< |
<syntaxhighlight lang="ring"> |
||
lp = fopen("/dev/lp0","w") fputs(lp,"Hello world!") fclose(lp) |
lp = fopen("/dev/lp0","w") fputs(lp,"Hello world!") fclose(lp) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|RPG}}== |
=={{header|RPG}}== |
||
{{works with|ILE RPG}} |
{{works with|ILE RPG}} |
||
<syntaxhighlight lang="rpg"> |
|||
<lang RPG> |
|||
Fqsysprt O F 80 printer |
Fqsysprt O F 80 printer |
||
C except |
C except |
||
Line 948: | Line 948: | ||
Oqsysprt E |
Oqsysprt E |
||
O 11 'Hello world' |
O 11 'Hello world' |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
Assumes that <code>lpr</code> command reaches printer. |
Assumes that <code>lpr</code> command reaches printer. |
||
< |
<syntaxhighlight lang="ruby">open("| lpr", "w") { |f| f.puts "Hello World!" }</syntaxhighlight> |
||
=={{header|Run BASIC}}== |
=={{header|Run BASIC}}== |
||
< |
<syntaxhighlight lang="runbasic"> shell$("echo \"Hello World!\" | lpr")</syntaxhighlight> |
||
=={{header|Rust}}== |
=={{header|Rust}}== |
||
===Unix=== |
===Unix=== |
||
< |
<syntaxhighlight lang="rust">use std::fs::OpenOptions; |
||
use std::io::Write; |
use std::io::Write; |
||
Line 966: | Line 966: | ||
let file = OpenOptions::new().write(true).open("/dev/lp0").unwrap(); |
let file = OpenOptions::new().write(true).open("/dev/lp0").unwrap(); |
||
file.write(b"Hello, World!").unwrap(); |
file.write(b"Hello, World!").unwrap(); |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Salmon}}== |
=={{header|Salmon}}== |
||
Assuming /dev/lp0 accesses the printer: |
Assuming /dev/lp0 accesses the printer: |
||
< |
<syntaxhighlight lang="salmon">open_output_text_file("/dev/lp0").print("Hello World!");</syntaxhighlight> |
||
Assuming lpr is a command that prints to a printer: |
Assuming lpr is a command that prints to a printer: |
||
< |
<syntaxhighlight lang="salmon">`echo "Hello World!" | lpr`;</syntaxhighlight> |
||
=={{header|Scala}}== |
=={{header|Scala}}== |
||
{{libheader|Scala}} |
{{libheader|Scala}} |
||
===All platforms=== |
===All platforms=== |
||
< |
<syntaxhighlight lang="scala">import java.awt.print.PrinterException |
||
import scala.swing.TextArea |
import scala.swing.TextArea |
||
Line 993: | Line 993: | ||
} |
} |
||
println("Document printed.") |
println("Document printed.") |
||
}</ |
}</syntaxhighlight> |
||
===[[Unix]]=== |
===[[Unix]]=== |
||
Assuming device is attached to lp0 |
Assuming device is attached to lp0 |
||
< |
<syntaxhighlight lang="scala">object LinePrinter extends App { |
||
import java.io.{ FileWriter, IOException } |
import java.io.{ FileWriter, IOException } |
||
{ |
{ |
||
Line 1,004: | Line 1,004: | ||
lp0.close() |
lp0.close() |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Scheme}}== |
=={{header|Scheme}}== |
||
===[[Unix]]=== |
===[[Unix]]=== |
||
Assuming device is attached to lp0 |
Assuming device is attached to lp0 |
||
< |
<syntaxhighlight lang="scheme">(call-with-output-file "/dev/lp0" |
||
(lambda (printer) |
(lambda (printer) |
||
(write "Hello World!" printer)))</ |
(write "Hello World!" printer)))</syntaxhighlight> |
||
=={{header|Seed7}}== |
=={{header|Seed7}}== |
||
Assuming that the line printer is attached to /dev/lp0: |
Assuming that the line printer is attached to /dev/lp0: |
||
< |
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i"; |
||
const proc: main is func |
const proc: main is func |
||
Line 1,024: | Line 1,024: | ||
writeln(lp, "Hello world!"); |
writeln(lp, "Hello world!"); |
||
close(lp); |
close(lp); |
||
end func;</ |
end func;</syntaxhighlight> |
||
=={{header|Sidef}}== |
=={{header|Sidef}}== |
||
< |
<syntaxhighlight lang="ruby">Sys.open(\var fh, '>', '/dev/lp0') \ |
||
&& fh.say("Hello World!") \ |
&& fh.say("Hello World!") \ |
||
&& fh.close</ |
&& fh.close</syntaxhighlight> |
||
=={{header|Simula}}== |
=={{header|Simula}}== |
||
{{works with|SIMULA-67}} |
{{works with|SIMULA-67}} |
||
< |
<syntaxhighlight lang="simula">BEGIN |
||
OUTTEXT("Hello World!"); |
OUTTEXT("Hello World!"); |
||
OUTIMAGE |
OUTIMAGE |
||
END</ |
END</syntaxhighlight> |
||
=={{header|Smalltalk}}== |
=={{header|Smalltalk}}== |
||
{{works with|Smalltalk/X}} |
{{works with|Smalltalk/X}} |
||
portable (dispatches to one of bellow): |
portable (dispatches to one of bellow): |
||
< |
<syntaxhighlight lang="smalltalk">s := PrinterStream defaultPrinter new. |
||
s nextPutLine:'Hello, world'. |
s nextPutLine:'Hello, world'. |
||
s close</ |
s close</syntaxhighlight> |
||
===[[Unix]]=== |
===[[Unix]]=== |
||
< |
<syntaxhighlight lang="smalltalk">s := PipeStream writingTo:'lpr'. |
||
s nextPutLine:'Hello, world'. |
s nextPutLine:'Hello, world'. |
||
s close.</ |
s close.</syntaxhighlight> |
||
alternative: |
alternative: |
||
< |
<syntaxhighlight lang="smalltalk">'/dev/lp0' asFilename writingFileDo:[:s | |
||
s nextPutLine:'Hello, world'. |
s nextPutLine:'Hello, world'. |
||
]</ |
]</syntaxhighlight> |
||
===[[Windows]]=== |
===[[Windows]]=== |
||
< |
<syntaxhighlight lang="smalltalk">s := WinPrinterStream new. |
||
s nextPutLine:'Hello, world'. |
s nextPutLine:'Hello, world'. |
||
s close.</ |
s close.</syntaxhighlight> |
||
=={{header|SNOBOL4}}== |
=={{header|SNOBOL4}}== |
||
Line 1,063: | Line 1,063: | ||
By default, the variable "input" is associated with standard input, and the variable "output" is associated with standard output. |
By default, the variable "input" is associated with standard input, and the variable "output" is associated with standard output. |
||
< |
<syntaxhighlight lang="snobol4"> output = "Hello, world."</syntaxhighlight> |
||
You can associate the variable "print" with lpt1 (the default local printer port) using the output() function: |
You can associate the variable "print" with lpt1 (the default local printer port) using the output() function: |
||
< |
<syntaxhighlight lang="snobol4"> output(.print,25,"lpt1") |
||
print = "Hello, world."</ |
print = "Hello, world."</syntaxhighlight> |
||
=={{header|Swift}}== |
=={{header|Swift}}== |
||
< |
<syntaxhighlight lang="swift">import Foundation |
||
let out = NSOutputStream(toFileAtPath: "/dev/lp0", append: true) |
let out = NSOutputStream(toFileAtPath: "/dev/lp0", append: true) |
||
Line 1,077: | Line 1,077: | ||
out?.open() |
out?.open() |
||
out?.write(UnsafePointer<UInt8>(data!.bytes), maxLength: data!.length) |
out?.write(UnsafePointer<UInt8>(data!.bytes), maxLength: data!.length) |
||
out?.close()</ |
out?.close()</syntaxhighlight> |
||
=={{header|Tcl}}== |
=={{header|Tcl}}== |
||
===[[Unix]]=== |
===[[Unix]]=== |
||
< |
<syntaxhighlight lang="tcl">exec lp << "Hello World!"</syntaxhighlight> |
||
< |
<syntaxhighlight lang="tcl">set f [open |lp w] |
||
puts $f "Hello World!" |
puts $f "Hello World!" |
||
close $f</ |
close $f</syntaxhighlight> |
||
===[[Windows]]=== |
===[[Windows]]=== |
||
< |
<syntaxhighlight lang="tcl">set f [open prn w] |
||
puts $f "Hello World!" |
puts $f "Hello World!" |
||
close $f</ |
close $f</syntaxhighlight> |
||
=={{header|UNIX Shell}}== |
=={{header|UNIX Shell}}== |
||
Use ''one'' of the following lines. |
Use ''one'' of the following lines. |
||
< |
<syntaxhighlight lang="bash"># Use the default printer queue, with lp(1) or lpr(1). |
||
# 1. The system must have a printer queue. |
# 1. The system must have a printer queue. |
||
# 2. The printer queue must understand plain text. |
# 2. The printer queue must understand plain text. |
||
Line 1,116: | Line 1,116: | ||
echo 'Hello World!' >/dev/lp0 |
echo 'Hello World!' >/dev/lp0 |
||
echo 'Hello World!' >/dev/lpt0 |
echo 'Hello World!' >/dev/lpt0 |
||
echo 'Hello World!' >/dev/ulpt0</ |
echo 'Hello World!' >/dev/ulpt0</syntaxhighlight> |
||
=={{header|Wisp}}== |
=={{header|Wisp}}== |
||
===[[Unix]]=== |
===[[Unix]]=== |
||
Assuming that the device is attached to lp0 |
Assuming that the device is attached to lp0 |
||
< |
<syntaxhighlight lang="wisp">call-with-output-file "/dev/lp0" |
||
λ : printer |
λ : printer |
||
write "Hello World!" printer</ |
write "Hello World!" printer</syntaxhighlight> |
||
=={{header|Wren}}== |
=={{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. |
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. |
||
< |
<syntaxhighlight lang="ecmascript">/* hello_world_line_printer.wren */ |
||
class C { |
class C { |
||
Line 1,133: | Line 1,133: | ||
} |
} |
||
C.lprint("Hello World!")</ |
C.lprint("Hello World!")</syntaxhighlight> |
||
<br> |
<br> |
||
We now embed this in the following C program, compile and run it. |
We now embed this in the following C program, compile and run it. |
||
< |
<syntaxhighlight lang="c">/* gcc hello_world_line_printer.c -o hello_world_line_printer -lwren -lm */ |
||
#include <stdio.h> |
#include <stdio.h> |
||
Line 1,197: | Line 1,197: | ||
free(script); |
free(script); |
||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
=={{header|X86 Assembly}}== |
=={{header|X86 Assembly}}== |
||
< |
<syntaxhighlight lang="asm">;Assemble with: tasm, tlink /t |
||
;assume direction bit is clear (so si increments) |
;assume direction bit is clear (so si increments) |
||
.model tiny |
.model tiny |
||
Line 1,217: | Line 1,217: | ||
msg db "Hello World!", 0ch, 0 ;0ch = form feed (for laser printer) |
msg db "Hello World!", 0ch, 0 ;0ch = form feed (for laser printer) |
||
end start</ |
end start</syntaxhighlight> |
||
=={{header|XPL0}}== |
=={{header|XPL0}}== |
||
< |
<syntaxhighlight lang="xpl0">code Text=12; |
||
Text(2, "Hello World! |
Text(2, "Hello World! |
||
");</ |
");</syntaxhighlight> |
||
The 2 directs the output to the printer (LPT1). |
The 2 directs the output to the printer (LPT1). |