Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Standard streams
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Timeline == === 1950s: Fortran === [[Fortran]] has the equivalent of Unix file descriptors: By convention, many Fortran implementations use unit numbers <code>UNIT=5</CODE> for stdin, <CODE>UNIT=6</CODE> for stdout and <CODE>UNIT=0</CODE> for stderr. In Fortran-2003, the intrinsic <code>ISO_FORTRAN_ENV</code> module was standardized to include the named constants <code>INPUT_UNIT</code>, <code>OUTPUT_UNIT</code>, and <code>ERROR_UNIT</code> to portably specify the unit numbers. <syntaxhighlight lang="fortran"> ! FORTRAN 77 example PROGRAM MAIN INTEGER NUMBER READ(UNIT=5,*) NUMBER WRITE(UNIT=6,'(A,I3)') ' NUMBER IS: ',NUMBER END </syntaxhighlight> <syntaxhighlight lang="fortran"> ! Fortran 2003 example program main use iso_fortran_env implicit none integer :: number read (unit=INPUT_UNIT,*) number write (unit=OUTPUT_UNIT,'(a,i3)') 'Number is: ', number end program </syntaxhighlight> === 1960: ALGOL 60=== [[ALGOL 60]] was criticized for having no standard file access.{{citation needed|date=February 2012}} === 1968: ALGOL 68=== [[ALGOL 68]]'s input and output facilities were collectively referred to as the transput.<ref>"[http://www.softwarepreservation.org/projects/ALGOL/report/Algol68_revised_report-AB.pdf Revised Report on the Algorithmic Language Algol 68]", edited by A. van Wijngaarden, B.J. Mailloux, J.E.L. Peck, C.H.A. Koster, M. Sintzoff, C.H. Lindsey, L.G.L.T. Meertens and R.G. Fisker, Section 10.3.</ref> [[Cornelis H. A. Koster|Koster]] coordinated the definition of the ''transput'' standard. The model included three standard channels: <code>stand in</code>, <code>stand out</code>, and <code>stand back</code>. {| |+ '''Example''' |colspan="2"|<syntaxhighlight lang="text"> # ALGOL 68 example # main:( REAL number; getf(stand in,($g$,number)); printf(($"Number is: "g(6,4)"OR "$,number)); # OR # putf(stand out,($" Number is: "g(6,4)"!"$,number)); newline(stand out) )</syntaxhighlight> |- !align="left"|Input: !align="left"|Output: |- |<pre>3.14159</pre> |<pre>Number is: +3.142 OR Number is: +3.142!</pre> |} === 1970s: C and Unix === In the [[C programming language]], the standard input, output, and error streams are attached to the existing Unix file descriptors 0, 1 and 2 respectively.<ref>{{Cite web|url=http://linux.die.net/man/3/stdin|title = Stdin(3): Standard I/O streams - Linux man page |website=die.net |url-status=live |archive-url=https://web.archive.org/web/20230608111413/https://linux.die.net/man/3/stdin |archive-date= Jun 8, 2023 }}</ref> In a [[POSIX]] environment the ''<[[unistd.h]]>'' definitions ''STDIN_FILENO'', ''STDOUT_FILENO'' or ''STDERR_FILENO'' should be used instead rather than [[Magic number (programming)|magic numbers]]. File pointers ''stdin'', ''stdout'', and ''stderr'' are also provided. [[Ken Thompson]] (designer and implementer of the original Unix operating system) modified [[sort (Unix)|sort]] in [[Version 5 Unix]] to accept "-" as representing standard input, which spread to other utilities and became a part of the operating system as a [[special file]] in [[Version 8 Unix|Version 8]]. Diagnostics were part of standard output through [[Version 6 Unix|Version 6]], after which [[Dennis M. Ritchie]] created the concept of standard error.<ref name="reader">{{cite tech report |first1=M. D. |last1=McIlroy |author-link1=Doug McIlroy |year=1987 |url=http://www.cs.dartmouth.edu/~doug/reader.pdf |title=A Research Unix reader: annotated excerpts from the Programmer's Manual, 1971โ1986 |series=CSTR |number=139 |institution=Bell Labs |url-status=live |archive-url=https://web.archive.org/web/20231215143742/https://www.cs.dartmouth.edu/~doug/reader.pdf |archive-date= Dec 15, 2023 }}</ref> ===1995: Java === In [[Java (programming language)|Java]], the standard streams are referred to by {{Javadoc:SE|java/lang|System|in}} (for stdin), {{Javadoc:SE|java/lang|System|out}} (for stdout), and {{Javadoc:SE|java/lang|System|err}} (for stderr).<ref>{{cite web|title=System (Java Platform SE 7)|url=http://docs.oracle.com/javase/7/docs/api/java/lang/System.html |website=Oracle Help Center |access-date=20 July 2012}}</ref> <syntaxhighlight lang="java"> public static void main(String args[]) { try { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s = br.readLine(); double number = Double.parseDouble(s); System.out.println("Number is:" + number); } catch (Exception e) { System.err.println("Error:" + e.getMessage()); } } </syntaxhighlight> ===2000s: .NET === In [[C Sharp (programming language)|C#]] and other [[.NET Framework|.NET]] languages, the standard streams are referred to by <code>System.Console.In</code> (for stdin), <code>System.Console.Out</code> (for stdout) and <code>System.Console.Error</code> (for stderr).<ref>{{Cite web|url=https://referencesource.microsoft.com/#mscorlib/system/console.cs,34|title= .NET Framework 4.7.1, mscorlib, console.cs |website=Reference Source - Microsoft |access-date=2017-12-10 |url-status=live |archive-url= https://web.archive.org/web/20171210072215/https://referencesource.microsoft.com/#mscorlib/system/console.cs,34 |archive-date= Dec 10, 2017 }}</ref> Basic read and write capabilities for the stdin and stdout streams are also accessible directly through the class <code>System.Console</code> (e.g. <code>System.Console.WriteLine()</code> can be used instead of <code>System.Console.Out.WriteLine()</code>). <code>System.Console.In</code>, <code>System.Console.Out</code> and <code>System.Console.Error</code> are <code>System.IO.TextReader</code> (stdin) and <code>System.IO.TextWriter</code> (stdout, stderr) objects, which only allow access to the underlying standard streams on a text basis. Full binary access to the standard streams must be performed through the <code>System.IO.Stream</code> objects returned by <code>System.Console.OpenStandardInput()</code>, <code>System.Console.OpenStandardOutput()</code> and <code>System.Console.OpenStandardError()</code> respectively. <syntaxhighlight lang="c#"> // C# example public static int Main(string[] args) { try { string s = System.Console.In.ReadLine(); double number = double.Parse(s); System.Console.Out.WriteLine("Number is: {0:F3}", number); return 0; // If Parse() threw an exception } catch (ArgumentNullException) { System.Console.Error.WriteLine("No number was entered!"); } catch (FormatException) { System.Console.Error.WriteLine("The specified value is not a valid number!"); } catch (OverflowException) { System.Console.Error.WriteLine("The specified number is too big!"); } return -1; } </syntaxhighlight> <syntaxhighlight lang="vbnet"> ' Visual Basic .NET example Public Function Main() As Integer Try Dim s As String = System.Console.[In].ReadLine() Dim number As Double = Double.Parse(s) System.Console.Out.WriteLine("Number is: {0:F3}", number) Return 0 ' If Parse() threw an exception Catch ex As System.ArgumentNullException System.Console.[Error].WriteLine("No number was entered!") Catch ex2 As System.FormatException System.Console.[Error].WriteLine("The specified value is not a valid number!") Catch ex3 As System.OverflowException System.Console.[Error].WriteLine("The specified number is too big!") End Try Return -1 End Function </syntaxhighlight> When applying the <code>System.Diagnostics.Process</code> [[class (computer science)|class]] one can use the instance [[Property (programming)|properties]] <code>StandardInput</code>, <code>StandardOutput</code>, and <code>StandardError</code> of that class to access the standard streams of the process. ===2000 - : Python (2 or 3) === The following example, written in [[Python (programming language)|Python]], shows how to redirect the standard input both to the standard output and to a text file. <syntaxhighlight lang="python" line="1"> #!/usr/bin/env python import sys # Save the current stdout so that we can revert sys.stdout # after we complete our redirection stdin_fileno = sys.stdin stdout_fileno = sys.stdout # Redirect sys.stdout to the file sys.stdout = open("myfile.txt", "w") ctr = 0 for inps in stdin_fileno: ctrs = str(ctr) # Prints to the redirected stdout () sys.stdout.write(ctrs + ") this is to the redirected --->" + inps + "\n") # Prints to the actual saved stdout handler stdout_fileno.write(ctrs + ") this is to the actual --->" + inps + "\n") ctr = ctr + 1 # Close the file sys.stdout.close() # Restore sys.stdout to our old saved file handler sys.stdout = stdout_fileno </syntaxhighlight> ===GUIs=== [[Graphical user interface]]s (GUIs) do not always make use of the standard streams; they do when GUIs are wrappers of underlying scripts and/or console programs, for instance the [[Synaptic (software)|Synaptic]] package manager GUI, which wraps apt commands in Debian and/or Ubuntu. GUIs created with scripting tools like Zenity and KDialog by [[KDE]] project<ref>{{cite web |url=https://www.linux-magazine.com/Issues/2009/99/Zenity-and-KDialog |first=Kristian |last=Kiรling |title=Adding graphic elements to your scripts with Zenity and KDialog |website=[[Linux Magazine]] |date=2009 |access-date=2021-04-11}}</ref> make use of stdin, stdout, and stderr, and are based on simple scripts rather than a complete GUI programmed and compiled in C/C++ using [[Qt (software)|Qt]], [[GTK]], or other equivalent proprietary widget framework. The [[Services menu]], as implemented on [[NeXTSTEP]] and [[Mac OS X]], is also analogous to standard streams. On these operating systems, graphical applications can provide functionality through a system-wide menu that operates on the current [[wikt:selection|selection]] in the GUI, no matter in what application. Some GUI programs, primarily on Unix, still write debug information to standard error. Others (such as many Unix media players) may read files from standard input. Popular Windows programs that open a separate console window in addition to their GUI windows are the emulators [[pSX (emulator)|pSX]] and [[DOSBox]]. [[GTK-server]] can use stdin as a communication interface with an interpreted program to realize a GUI. The [[CLIM|Common Lisp Interface Manager]] paradigm "presents" GUI elements sent to an extended output stream.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)