Hello world/Standard error: Difference between revisions

Content added Content deleted
(jq)
m ({{out}} / -Category:Scala Implementations / moved Category to top)
Line 1:
{{task|Basic language learning}} {{selection|Short Circuit|Console Program Basics}}
{{task|Basic language learning}}{{selection|Short Circuit|Console Program Basics}}A common practice in computing is to send error messages to a different output stream than [[User Output - text|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.
[[Category:Streams]]
{{omit from|Applesoft BASIC}}
{{omit from|bc|Always prints to standard output.}}
{{omit from|Brainf***}}
{{omit from|dc|Always prints to standard output.}}
{{omit from|GUISS|Cannot customize error messages}}
{{omit from|Integer BASIC}}
{{omit from|TI-83 BASIC|Same reason as TI-89.}}
{{omit from|TI-89 BASIC|no analogue to stderr, unless you count graph display vs. program IO}}
{{omit from|Unlambda|No concept of standard error (or alternate output streams in general).}}
 
A common practice in computing is to send error messages
to a different output stream than [[User Output - text|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.
Line 29 ⟶ 47:
put(stand error, ("Goodbye, World!", new line))
)</lang>
{{out}}
Output:
<pre>
Goodbye, World!
Line 62 ⟶ 80:
 
=={{header|AWK}}==
To print a message to standard error,
Pipepipe it through a shell command:
 
<lang awk>BEGIN {
Line 77 ⟶ 96:
}</lang>
 
With ''gawk'', ''mawk'' and ''nawk'': a special feature associates "/dev/stderr" with standard error. The manuals of ''gawk'' and ''mawk'' describe this feature; ''nawk'' also has this feature.
associates "/dev/stderr" with standard error.
The manuals of ''gawk'' and ''mawk'' describe this feature;
''nawk'' also has this feature.
 
Other implementations might try to open /dev/stderr as a file.
Other implementations might try to open /dev/stderr as a file. Some Unix clones, like [[BSD]], have a /dev/stderr device node that duplicates standard error, so this code would still work. Some systems have no such device node, so this code would fail. We recommend "cat 1>&2", which is more portable, and works with any Unix clone.
Some Unix clones, like [[BSD]], have a /dev/stderr device node
that duplicates standard error, so this code would still work.
Some systems have no such device node, so this code would fail.
We recommend "cat 1>&2", which is more portable, and works with any Unix clone.
 
=={{header|Batch File}}==
<lang dos>1>&2 echo Goodbye, World!</lang>
The redirection operator <code>1>&2</code> causes all output on stream 1 (standard out) to be redirected to stream 2 (standard error). The redirection can be moved to the end of the line, too.
The redirection can be moved to the end of the line, too.
 
=={{header|BASIC}}==
Line 115 ⟶ 142:
return 0;
}</lang>
 
=={{header|C sharp|C#}}==
<lang csharp>static class StdErr
Line 225 ⟶ 253:
 
=={{header|Factor}}==
Start Factor in a terminal for this.:
<lang factor>error-stream get [ "Goodbye, World! bbl, crashing" print flush ] with-output-stream*</lang>
 
Line 249 ⟶ 277:
=={{header|Fortran}}==
 
Normally standard error is associated with the unit 0 but this could be different for different vendors. Therefore since Fortran 2003 there's an intrinsic module which defines the parameter ERROR_UNIT.
but this could be different for different vendors.
Therefore since Fortran 2003 there's an intrinsic module
which defines the parameter ERROR_UNIT.
 
<lang fortran>program StdErr
Line 318 ⟶ 349:
<lang jq>error("Goodbye, World!")</lang>
 
Note that although this satisfies the task requirement, error/1 also raises an error condition.
error/1 also raises an error condition.
 
=={{header|Julia}}==
<lang julia>println(STDERR, "Goodbye, World!")</lang>
Line 425 ⟶ 458:
END HelloErr.
</lang>
{{out}}
Output:
<pre>
Goodbye, World!
</pre>
 
=={{header|Objective-C}}==
 
Line 434 ⟶ 468:
{{Works with|Cocoa}}
 
In Objective-C one can use the standard C library and the stderr as in the C language; nonetheless a common way to output to stderr for logging purpose and/or error notification is the <tt>NSLog</tt> function, that works almost like <tt>fprintf(stderr, "...")</tt>, save for the fact that the format string is an NSString object, and it also prepends a timestamp.
is an NSString object, and it also prepends a timestamp.
 
<lang objc>#import <Foundation/Foundation.h>
Line 466 ⟶ 501:
ooRexx provides a .error object that writes output to the standard error stream.
<lang ooRexx>.error~lineout("Goodbye, World!")</lang>
The .error object is a proxy that delegates to a backing stream, so this might be redirected. By default, this delegates to the .stderr object, which can also be used directly.
By default, this delegates to the .stderr object, which can also be used directly.
<lang ooRexx>.stderr~lineout("Goodbye, World!")</lang>
or in 'Classic REXX style'
Line 531 ⟶ 567:
 
=={{header|PowerShell}}==
Since PowerShell has a slightly different system of pipes and streams (to facilitate easy usage from a host application) the standard Write-Error cmdlet is mainly for sending annotated error messages to the host:
(to facilitate easy usage from a host application) the
standard Write-Error cmdlet is mainly for sending annotated error messages
to the host:
<lang powershell>Write-Error "Goodbye, World!"</lang>
Note that this outputs more than just the message, because behind the scenes it is an uncaught exception:
because behind the scenes it is an uncaught exception:
<pre>Write-Error "Goodbye, World!" : Goodbye, World!
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
Line 578 ⟶ 618:
=={{header|REXX}}==
===version 1===
This version will work with any REXX under operating systems (hosts) that don't have (or support) either stream output,
that don't have (or support) either stream output,
<br>or don't have a specific &nbsp; '''STDERR''' &nbsp; output steam (or a method of writing to one), &nbsp; or have the &nbsp; '''stderr''' &nbsp; device driver
<br>disabled &nbsp; (the "driver" may be known as a different name), &nbsp; or if the REXX doesndon't utilizehave or bypassesa thespecific &nbsp; '''stderrSTDERR''' &nbsp; deviceoutput steam
<br>or don't have a specific &nbsp; '''STDERR''' &nbsp; output steam (or a method of writing to one), &nbsp; or have the &nbsp; '''stderr''' &nbsp; device driver
<br>driver. &nbsp; Some or all of the above restrictions generally refer to the older/legacy REXXes.
<br>disabled &nbsp; (the "driver" may be known as a different name), &nbsp; or if the REXX doesn't utilize or bypasses the &nbsp; '''stderr''' &nbsp; device driver.<br>
<br>driver. &nbsp; Some or all of the above restrictions generally refer to the older/legacy REXXes.
<br>The output (below) is goes to the terminal/console &nbsp; (which is the destination for all normal and error messages).
<lang rexx>say 'Goodbye, World!'</lang>
 
===version 2===
This version will work with those operating systems (hosts) that support stream output and a &nbsp; STDERR &nbsp; output
that support stream output and a &nbsp; STDERR &nbsp; output
<br>stream (by name).
<br>If the &nbsp; '''stderr''' &nbsp; name is supported and enabled, the output is written to the terminal.
Line 624 ⟶ 667:
document.write('Goodbye, World!');
</script>""</lang>
Run Basic runs in a browser. This opens a new browser window, or a tab in the case of Chrome and some others.
This opens a new browser window,
or a tab in the case of Chrome and some others.
 
=={{header|Rust}}==
Line 672 ⟶ 717:
 
=={{header|Scala}}==
[[Category:Scala Implementations]]
{{libheader|Console}}
 
===Ad hoc REPL solution===
Ad hoc solution as [http://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop REPL] script:
<lang Scala>Console.err.println("Goodbye, World!")</lang>
 
===Via Java runtime===
This is a call to the Java run-time library. '''Not recommendated'''.
<lang Scala>System.err.println("Goodbye, World!")</lang>
 
===Via Scala Console API===
This is a call to the Scala API. '''Recommendated'''.
<lang Scala>Console.err.println("Goodbye, World!")</lang>
 
===Short term deviation to err===
<lang Scala>Console.withOut(Console.err) { println("This goes to default _err_") }</lang>
 
===Long term deviation to err===
<lang Scala> println ("Out not deviated")
Line 702 ⟶ 751:
}</lang>
 
This program requires at least 1 line of input. It changes the first line to "Goodbye, World!" and then prints the first line to standard error. It reads and ignores the remaining lines.
It changes the first line to "Goodbye, World!"
and then prints the first line to standard error.
It reads and ignores the remaining lines.
 
Test output: <lang bash>$ echo a | sed -f error.sed >/dev/null
Line 731 ⟶ 783:
=={{header|Tcl}}==
<lang tcl>puts stderr "Goodbye, World!"</lang>
 
=={{header|TUSCRIPT}}==
<lang tuscript>
Line 738 ⟶ 791:
PRINT/ERROR text
</lang>
{{out}}
Output:
<pre>
@@@@@@@@ hello world @@@@@@@@
Line 751 ⟶ 804:
<lang csh>echo "Goodbye, World!" >/dev/stderr</lang>
 
This requires <code>/dev/stderr</code>, a device node from [[BSD]] and some other Unix clones. This command works with both Bourne Shell and C Shell.
and some other Unix clones.
This command works with both Bourne Shell and C Shell.
 
=={{header|X86 Assembly}}==
Line 778 ⟶ 833:
 
=={{header|XPL0}}==
The terms "standard output" and "standard error" are not used, but it's
but it's trivial to send messages to a variety of devices by specifying their
by specifying their numbers.
numbers. Normally messages are displayed on the text console, which is device 0.
device 0. Instead, this example sends the message to the (first) printer,
which is device 2.
 
Line 789 ⟶ 845:
=={{header|zkl}}==
<lang zkl>File.stderr.writeln("Goodbye, World!")</lang>
 
 
{{omit from|Applesoft BASIC}}
{{omit from|bc|Always prints to standard output.}}
{{omit from|Brainf***}}
{{omit from|dc|Always prints to standard output.}}
{{omit from|GUISS|Cannot customize error messages}}
{{omit from|Integer BASIC}}
{{omit from|TI-83 BASIC|Same reason as TI-89.}}
{{omit from|TI-89 BASIC|no analogue to stderr, unless you count graph display vs. program IO}}
{{omit from|Unlambda|No concept of standard error (or alternate output streams in general).}}
 
[[Category:Streams]]