Hello world/Standard error: Difference between revisions
(add E example) |
|||
Line 3: | Line 3: | ||
Show how to print a message to standard error by printing "Goodbye, World!" on that stream. |
Show how to print a message to standard error by printing "Goodbye, World!" on that stream. |
||
=={{header|ALGOL 68}}== |
|||
The procedures <code>print</code> and <code>printf</code> output to ''stand out'', |
|||
whereas <code>put</code> and <code>putf</code> can output to any open '''FILE''', including ''stand error''. |
|||
{{works with|ALGOL 68|Standard - no extensions to language used}} |
|||
{{works with|ALGOL 68G|Any - tested with release mk15-0.8b.fc9.i386}} |
|||
{{works with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release 1.8.8d.fc9.i386}} |
|||
<pre> |
|||
main:( |
|||
put(stand error, ("Goodbye, World!", new line)) |
|||
) |
|||
</pre> |
|||
Output: |
|||
<pre> |
|||
Goodbye, World! |
|||
</pre> |
|||
=={{header|C}}== |
=={{header|C}}== |
||
Unlike puts(), fputs() does not append a terminal newline. |
Unlike puts(), fputs() does not append a terminal newline. |
||
Line 15: | Line 31: | ||
} |
} |
||
</c> |
</c> |
||
=={{header|C++}}== |
=={{header|C++}}== |
||
<cpp>#include <iostream> |
<cpp>#include <iostream> |
Revision as of 05:33, 12 January 2009
![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.
A common practice in computing is to send error messages to a different output stream than normal text console messages. The normal messages print to what is called "standard output" or "standard out". The error messages print to "standard error". This separation can be used to redirect error messages to a different place than normal messages.
Show how to print a message to standard error by printing "Goodbye, World!" on that stream.
ALGOL 68
The procedures print
and printf
output to stand out,
whereas put
and putf
can output to any open FILE, including stand error.
main:( put(stand error, ("Goodbye, World!", new line)) )
Output:
Goodbye, World!
C
Unlike puts(), fputs() does not append a terminal newline. <c>#include <stdio.h>
int main() { fprintf(stderr, "Goodbye, "); fputs("World!\n", stderr);
return 0; } </c>
C++
<cpp>#include <iostream>
using std::cerr; using std::endl;
int main () {
cerr << "Goodbye, World!" << endl;
return 0;
}</cpp>
E
stderr.println("Goodbye, World!")
Forth
outfile-id stderr to outfile-id ." Goodbye, World!" cr to outfile-id
Haskell
import System.IO hPutStrLn stderr "Goodbye, World!"
Java
<java>public class Err{
public static void main(String[] args){ System.err.println("Goodbye, World!"); }
}</java>
Modula-3
MODULE Stderr EXPORTS Main; IMPORT Wr, Stdio; BEGIN Wr.PutText(Stdio.stderr, "Goodbye, World!\n"); END Stderr.
OCaml
<ocaml>prerr_endline "Goodbye, World!"; (* this is how you print a string with newline to stderr *) Printf.eprintf "Goodbye, World!\n"; (* this is how you would use printf with stderr *)</ocaml>
Perl
<perl>print STDERR "Goodbye, World!\n";</perl>
PHP
<php>fprintf(STDERR, "Goodbye, World!\n");</php>
Python
<python>import sys
print >> sys.stderr, "Goodbye, World!"</python>
<python>import sys
print("Goodbye, World!", file=sys.stderr)</python>
Ruby
$stderr.puts("Goodbye, World!")
UNIX Shell
echo "Goodbye, World!" > /dev/stderr