Hello world/Standard error: Difference between revisions

From Rosetta Code
Content added Content deleted
(added ruby)
(added ocaml)
Line 40: Line 40:
}
}
}</java>
}</java>

=={{header|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>


=={{header|Perl}}==
=={{header|Perl}}==

Revision as of 00:48, 8 January 2009

Task
Hello world/Standard error
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.

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>

Forth

Works with: GNU Forth
outfile-id
  stderr to outfile-id
  ." Goodbye, World!" cr
to outfile-id

Java

<java>public class Err{

  public static void main(String[] args){
     System.err.println("Goodbye, World!");
  }

}</java>

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>

Python

2.x

<python>import sys

print >> sys.stderr, "Goodbye, World!"</python>

3.x

<python>import sys

print("Goodbye, World!", file=sys.stderr)</python>

Ruby

$stderr.puts("Goodbye, World!")

UNIX Shell

echo "Goodbye, World!" > /dev/stderr