Hello world/Line printer: Difference between revisions
→{{header|Java}}: I'm just removing this. This wasn't even close, and it probably requires a little-used third party library anyway. |
|||
Line 54: | Line 54: | ||
<lang j>require'print' |
<lang j>require'print' |
||
print'Hello world!'</lang> |
print'Hello world!'</lang> |
||
=={{header|Java}}== |
|||
{{incorrect|Java|Outputs to stdout}} |
|||
<lang java> |
|||
public class HelloWorld { |
|||
public static void main(String[] args) { |
|||
System.out.println("Hello world!"); |
|||
} |
|||
} |
|||
</lang> |
|||
=={{header|PHP}}== |
=={{header|PHP}}== |
Revision as of 18:44, 8 January 2011
![Task](http://static.miraheze.org/rosettacodewiki/thumb/b/ba/Rcode-button-task-crushed.png/64px-Rcode-button-task-crushed.png)
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
<lang qbasic>LPRINT "Hello World!"</lang>
Batch File
<lang dos>ECHO Hello world!>PRN</lang>
C++
<lang cpp>#include <iostream>
int main() {
std::cout << "Hello world!" << std::endl; // std::endl provides a portable descriptor for line ending. return 0;
}</lang>
Factor
<lang factor> USE: io IN: hello-world
- hello ( -- ) "Hello World!" print ;
MAIN: hello</lang>
when you want a fully working program or in the listener:
<lang factor>"Hello World!" print</lang>
Haskell
<lang haskell> import System.Cmd
cmd = "echo \"Hello World!\" | lpr"
main = system cmd </lang>
J
<lang j>require'print' print'Hello world!'</lang>
PHP
<lang PHP><?php echo 'Hello world!'; ?></lang>
PicoLisp
<lang PicoLisp>(out '(lpr "-P" "Printer01")
(prinl "Hello world") )</lang>
PureBasic
<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>
Python
Assuming that the line printer is attached to /dev/lp0 <lang python>lp = open("/dev/lp0") lp.write("Hello World!/n") lp.close()</lang>
REXX
There is no direct way for REXX programs to write to the printer, but
a shell command could be used.
In DOS (or under Windows):
<lang rexx>
str='Hello World'
'@ECHO' str ">PRN"
</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
<lang bash>echo 'Hello World!'|lp</lang>
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>