尿道感染看什么科| 泡鲁达是什么| 子宫内膜异位症有什么症状| 解神是什么意思| 吃什么补肝养肝| rds医学上什么意思| 今年男宝宝取什么名字好| 明媚是什么意思| 肾结石是什么| 71岁属什么| 吃什么排毒| 空调制冷量是什么意思| 为什么纯牛奶容易爆痘| 扑热息痛又叫什么名| 广东古代叫什么| 马黛茶什么味道| 发烧头晕吃什么药| 纳豆什么味道| 男人脚肿是什么病的前兆| 国师是什么生肖| 间质性肺炎是什么意思| 鼻尖长痣代表什么| 韩红什么军衔| 脑卒中什么意思| 世界上最大的单位是什么| 指甲黑线是什么原因| 睡不着觉什么原因| 反社会人格有什么表现| 华堂是什么意思| 染色体变异发生在什么时期| flair呈高信号是什么意思| 驻唱是什么意思| 呕血是什么意思| 吃海鲜不能吃什么| 吃山药有什么好处| 胸口出汗是什么原因| 妍什么意思| 木九十眼镜什么档次| 昔人是什么意思| 心脏属于什么组织| 叶酸买什么牌子的好| 进字五行属什么| 洋葱什么时候收获| 能力是什么| 自讨没趣什么意思| 淤血是什么意思| 水浒传有什么故事| 什么是结核病| 派特ct主要检查什么| 小鸭吃什么| ab型血为什么容易得精神病| 枯木逢春什么意思| 荨麻疹是什么样的| 袢是什么意思| romantic是什么意思| 五行木是什么颜色| 男性腰疼挂什么科| 2006属狗的五行缺什么| 立春是什么生肖| 剧情是什么意思| 为什么硬不起来| s925是什么金| 举贤不避亲什么意思| 什么人不穿衣服| 享受低保需要什么条件| 995是什么意思| 双侧卵巢显示不清是什么意思| 尿酸高肌酐高是什么原因呢| egm是什么意思| 过敏性紫癜挂什么科| 双子座男生喜欢什么样的女生| 送人梳子的寓意是什么| dna是什么| 井井有条是什么意思| 桃子跟什么不能一起吃| 荏苒是什么意思| 女汉子什么意思| 大校相当于地方什么级别| 医学五行属什么| 仕途是什么意思| 湍急是什么意思| 梦见办酒席是什么意思| 儿童办护照需要什么材料| 新陈代谢是指什么| 人是由什么组成的| 碱性磷酸酶偏高吃什么能降下来呢| mf是什么意思| 低血压和低血糖有什么区别| 确认妊娠是什么意思啊| 女人更年期什么症状| 湖南湖北以什么湖为界| 9-11点是什么时辰| 什么样的风景| 借鸡生蛋是什么意思| 治疗勃起困难有什么药| 汞中毒是什么症状| 匀字五行属什么| 一什么春笋| 春秋大梦是什么意思| 血压高什么原因引起的| 地铁什么时候停运| 柳絮吃了有什么好处| 麒字五行属什么| 手心脚心发热吃什么药| 胸闷心慌是什么病| 女生肚脐眼下面疼是什么原因| 消渴症是什么病| 陈皮有什么功效| 女人脸色发黄吃什么补得最快| 皮肤经常痒是什么原因| 舌尖疼是什么原因| 桑葚有什么功效| 夜晚睡不着觉什么原因| 14年是什么年| 猫砂是什么材料做的| 格桑是什么意思| NF什么意思| cheese是什么意思| 中午一点是什么时辰| 去香港澳门旅游需要准备什么| 横空出世是什么意思| 治类风湿用什么方法好| ptc是什么意思| 反流性食管炎可以吃什么水果| zuczug是什么牌子| 关节咔咔响是什么原因| 什么样的女人招人嫉妒| 针对性是什么意思| 北宋六贼为什么没高俅| 武则天是什么朝代的| 血红蛋白偏低吃什么补| 一字马是什么意思| 东南大学什么专业最牛| 巴旦木是什么树的果实| 胃疼吃什么药好| 杭州菜属于什么菜系| 行了是什么意思| 孕吐反应什么时候开始| 羊与什么生肖相合| 气泡音是什么意思| 疥疮是什么| 后背疼痛什么原因| 梦见两个小男孩是什么意思| 破伤风有什么作用| lg是什么牌子| 颞下颌关节紊乱吃什么药| 肝阴不足吃什么中成药| 孩子容易出汗是什么原因| 附件炎吃什么药好| 儿童舌系带短挂什么科| 小米粥配什么菜好吃| 每年什么时候最热| 麝香是什么东西| 猫咪泪痕重是什么原因| 头晕头疼挂什么科| 6月份怀孕预产期是什么时候| 眉毛长痘是什么原因| 为什么金生水| 脚掌发麻是什么原因| 孕晚期高血压对胎儿有什么影响| innisfree是什么牌子的化妆品| 什么动物的血是蓝色的| 换肾是什么病| 尿蛋白两个加号是什么意思| 无聊可以干什么| 放疗后吃什么恢复快| 王大治与董洁什么关系| 猫在风水上代表什么| 什么是地沟油| 呦西是什么意思| r商标是什么意思| 醋坛子是什么意思| 动车是什么| 赡养是什么意思| 古代男子成年叫什么| 孕中期宫缩是什么感觉| 于心不忍是什么意思| 兵解是什么意思| 代价什么意思| 眩晕停又叫什么| 尿酸高是什么原因引起的| 胃结石有什么症状表现| 耳鸣吃什么药最有效| 五行中什么生木| 长辈生日送什么花| 永垂不朽什么意思| 一贫如什么| 肝有什么功能| 底线是什么意思| 腿肿脚肿是什么原因引起的| 白带带血是什么原因| 男生下面叫什么| 无冕之王是什么意思| 财年是什么意思| 什么其谈| 小美女是什么意思| 宫寒有什么症状| 陈皮泡水喝有什么好处| 本卦和变卦是什么关系| 闪光点是什么意思| 鼻塞是什么原因| 114514什么意思| 黄芪丹参山楂泡水有什么功效| 什么是低保户| 长脸型适合什么样的发型| 脚长水泡是什么原因| 经期喝酒会有什么危害| 黄瓜为什么是苦的| tct和hpv有什么区别| 小孩流口水是什么原因| 心脏右束支传导阻滞是什么意思| 黄什么什么| 疤痕增生是什么| 6月28什么星座| 大小脸去医院挂什么科| 24k镀金是什么意思| nf是什么| 眼睛肿是什么问题| 鳞状上皮细胞是什么| 什么花不能浇水| 孩子疱疹性咽峡炎吃什么药| mn是什么单位| 脐下三寸是什么地方| 精制盐是什么盐| 血脂稠喝什么茶效果好| 坐班是什么意思| 李嘉诚戴的什么手表| 为什么头皮总是很痒| 为什么会得卵巢癌| 炼乳是什么| 吃蓝莓有什么好处| 辅食是什么意思| 二月二十二日是什么星座| 跑马什么意思| 经常吃紧急避孕药有什么危害| 为什么家里会有蟑螂| 清明有什么习俗| 用你的手解我的锁是什么歌| 乙肝阴性是什么意思| 本命佛是什么意思| 吃维e有什么好处和副作用| 不带壳的蜗牛叫什么| 什么是大三阳| 75年属什么的生肖| 付字五行属什么| 梅毒病有什么症状| 海明威为什么自杀| cpi指数上涨意味着什么| 电脑长期不关机有什么影响| 孔雀鱼吃什么食物| 炉鼎是什么意思| 晚上九点多是什么时辰| camper是什么牌子| 莳字五行属什么| 什么叫脘腹胀痛| 早孕试纸什么时候测最准确| animals什么意思| 多子多福是什么意思| 尿蛋白十一什么意思| 原研药是什么意思| 毛主席什么时候去世| 透明人什么意思| 女性大腿酸痛什么原因| 鸡蛋和面粉可以做什么好吃的| 百度Jump to content

国内--陕西频道--人民网

From Wikipedia, the free encyclopedia
(Redirected from Standard output)
百度 主要违法违规事实(案由)分别是“以固有财产与信托财产进行交易”和“未按监管要求计提拨备”。

In computer programming, standard streams are preconnected input and output communication channels[1] between a computer program and its environment when it begins execution. The three input/output (I/O) connections are called standard input (stdin), standard output (stdout) and standard error (stderr). Originally I/O happened via a physically connected system console (input via keyboard, output via monitor), but standard streams abstract this. When a command is executed via an interactive shell, the streams are typically connected to the text terminal on which the shell is running, but can be changed with redirection or a pipeline. More generally, a child process inherits the standard streams of its parent process.

Application

[edit]
The standard streams for input, output, and error in a common default configuration

Users generally know standard streams as input and output channels that handle data coming from an input device, or that write data from the application. The data may be text with any encoding, or binary data. When a program is run as a daemon, its standard error stream is redirected into a log file, typically for error analysis purposes.

Streams may be used to chain applications, meaning that the output stream of one program can be redirected to be the input stream to another application. In many operating systems this is expressed by listing the application names, separated by the vertical bar character, for this reason often called the pipeline character. A well-known example is the use of a pagination application, such as more, providing the user control over the display of the output stream on the display.

Background

[edit]

In most operating systems predating Unix, programs had to explicitly connect to the appropriate input and output devices. OS-specific intricacies caused this to be a tedious programming task. On many systems it was necessary to obtain control of environment settings, access a local file table, determine the intended data set, and handle hardware correctly in the case of a punch card reader, magnetic tape drive, disk drive, line printer, card punch, or interactive terminal.

One of Unix's several groundbreaking advances was abstract devices, which removed the need for a program to know or care what kind of devices it was communicating with[citation needed]. Older operating systems forced upon the programmer a record structure and frequently non-orthogonal data semantics and device control. Unix eliminated this complexity with the concept of a data stream: an ordered sequence of data bytes which can be read until the end of file. A program may also write bytes as desired and need not, and cannot easily declare their count or grouping.

Another Unix breakthrough was to automatically associate input and output to terminal keyboard and terminal display, respectively, by default[citation needed] — the program (and programmer) did absolutely nothing to establish input and output for a typical input-process-output program (unless it chose a different paradigm). In contrast, previous operating systems usually required some—often complex—job control language to establish connections, or the equivalent burden had to be orchestrated by the program.[citation needed]

Since Unix provided standard streams, the Unix C runtime environment was obliged to support it as well. As a result, most C runtime environments (and C's descendants), regardless of the operating system, provide equivalent functionality.

Standard input (stdin)

[edit]

Standard input is a stream from which a program reads its input data. The program requests data transfers by use of the read operation. Not all programs require stream input. For example, the dir and ls programs (which display file names contained in a directory) may take command-line arguments, but perform their operations without any stream data input.

Unless redirected, standard input is inherited from the parent process. In the case of an interactive shell, that is usually associated with the input device of a terminal (or pseudo terminal) which is ultimately linked to a user's keyboard.

On POSIX systems, the file descriptor for standard input is 0 (zero); the POSIX <unistd.h> definition is STDIN_FILENO; the corresponding C <stdio.h> abstraction is provided via the FILE* stdin global variable. Similarly, the global C++ std::cin variable of type <iostream> provides an abstraction via C++ streams. Similar abstractions exist in the standard I/O libraries of practically every programming language.

Standard output (stdout)

[edit]

Standard output is a stream to which a program writes its output data. The program requests data transfer with the write operation. Not all programs generate output. For example, the file rename command (variously called mv, move, or ren) is silent on success.

Unless redirected, standard output is inherited from the parent process. In the case of an interactive shell, that is usually the text terminal which initiated the program.

The file descriptor for standard output is 1 (one); the POSIX <unistd.h> definition is STDOUT_FILENO; the corresponding C <stdio.h> variable is FILE* stdout; similarly, the C++ <iostream> variable is std::cout.

Standard error (stderr)

[edit]

Standard error is another output stream typically used by programs to output error messages or diagnostics. It is a stream independent of standard output and can be redirected separately.

This solves the semi-predicate problem, allowing output and errors to be distinguished, and is analogous to a function returning a pair of values – see Semipredicate problem § Multivalued return. The usual destination is the text terminal which started the program to provide the best chance of being seen even if standard output is redirected (so not readily observed). For example, output of a program in a pipeline is redirected to input of the next program or a text file, but errors from each program still go directly to the text terminal so they can be reviewed by the user in real time.

It is acceptable and normal to direct standard output and standard error to the same destination, such as the text terminal. Messages appear in the same order as the program writes them, unless buffering is involved. For example, in common situations the standard error stream is unbuffered but the standard output stream is line-buffered; in this case, text written to standard error later may appear on the terminal earlier, if the standard output stream buffer is not yet full.

The file descriptor for standard error is defined by POSIX as 2 (two); the <unistd.h> header file provides the symbol STDERR_FILENO;[2] the corresponding C <stdio.h> variable is FILE* stderr. The C++ <iostream> standard header provides two variables associated with this stream: std::cerr and std::clog, the former being unbuffered and the latter using the same buffering mechanism as all other C++ streams.

Bourne-style shells allow standard error to be redirected to the same destination that standard output is directed to using

 2>&1

csh-style shells allow standard error to be redirected to the same destination that standard output is directed to using

 >&

Standard error was added to Unix in the 1970s after several wasted phototypesetting runs ended with error messages being typeset instead of displayed on the user's terminal.[3]

Timeline

[edit]

1950s: Fortran

[edit]

Fortran has the equivalent of Unix file descriptors: By convention, many Fortran implementations use unit numbers UNIT=5 for stdin, UNIT=6 for stdout and UNIT=0 for stderr. In Fortran-2003, the intrinsic ISO_FORTRAN_ENV module was standardized to include the named constants INPUT_UNIT, OUTPUT_UNIT, and ERROR_UNIT to portably specify the unit numbers.

! FORTRAN 77 example
      PROGRAM MAIN
        INTEGER NUMBER
        READ(UNIT=5,*) NUMBER
        WRITE(UNIT=6,'(A,I3)') ' NUMBER IS: ',NUMBER
      END
! 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

1960: ALGOL 60

[edit]

ALGOL 60 was criticized for having no standard file access.[citation needed]

1968: ALGOL 68

[edit]

ALGOL 68's input and output facilities were collectively referred to as the transput.[4] Koster coordinated the definition of the transput standard. The model included three standard channels: stand in, stand out, and stand back.

Example
# 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)
)
Input: Output:
3.14159
Number is: +3.142 OR Number is: +3.142!

1970s: C and Unix

[edit]

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.[5] In a POSIX environment the <unistd.h> definitions STDIN_FILENO, STDOUT_FILENO or STDERR_FILENO should be used instead rather than magic numbers. File pointers stdin, stdout, and stderr are also provided.

Ken Thompson (designer and implementer of the original Unix operating system) modified 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. Diagnostics were part of standard output through Version 6, after which Dennis M. Ritchie created the concept of standard error.[6]

1995: Java

[edit]

In Java, the standard streams are referred to by System.in (for stdin), System.out (for stdout), and System.err (for stderr).[7]

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());
    }
}

2000s: .NET

[edit]

In C# and other .NET languages, the standard streams are referred to by System.Console.In (for stdin), System.Console.Out (for stdout) and System.Console.Error (for stderr).[8] Basic read and write capabilities for the stdin and stdout streams are also accessible directly through the class System.Console (e.g. System.Console.WriteLine() can be used instead of System.Console.Out.WriteLine()).

System.Console.In, System.Console.Out and System.Console.Error are System.IO.TextReader (stdin) and System.IO.TextWriter (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 System.IO.Stream objects returned by System.Console.OpenStandardInput(), System.Console.OpenStandardOutput() and System.Console.OpenStandardError() respectively.

// 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;
}
' 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

When applying the System.Diagnostics.Process class one can use the instance properties StandardInput, StandardOutput, and StandardError of that class to access the standard streams of the process.

2000 - : Python (2 or 3)

[edit]

The following example, written in Python, shows how to redirect the standard input both to the standard output and to a text file.

#!/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

GUIs

[edit]

Graphical user interfaces (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 package manager GUI, which wraps apt commands in Debian and/or Ubuntu. GUIs created with scripting tools like Zenity and KDialog by KDE project[9] 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, 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 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 and DOSBox.

GTK-server can use stdin as a communication interface with an interpreted program to realize a GUI.

The Common Lisp Interface Manager paradigm "presents" GUI elements sent to an extended output stream.

See also

[edit]

References

[edit]
  1. ^ D. M. Ritchie, "A Stream Input-Output System", AT&T Bell Laboratories Technical Journal, 68(8), October 1984.
  2. ^ "<unistd.h>". The Open Group Base Specifications Issue 6—IEEE Std 1003.1, 2004 Edition. The Open Group. 2004.
  3. ^ Johnson, Steve (2025-08-06). "[TUHS] Graphic Systems C/A/T phototypesetter" (Mailing list). Archived from the original on 2025-08-06. Retrieved 2025-08-06.
  4. ^ "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.
  5. ^ "Stdin(3): Standard I/O streams - Linux man page". die.net. Archived from the original on Jun 8, 2023.
  6. ^ McIlroy, M. D. (1987). A Research Unix reader: annotated excerpts from the Programmer's Manual, 1971–1986 (PDF) (Technical report). CSTR. Bell Labs. 139. Archived (PDF) from the original on Dec 15, 2023.
  7. ^ "System (Java Platform SE 7)". Oracle Help Center. Retrieved 20 July 2012.
  8. ^ ".NET Framework 4.7.1, mscorlib, console.cs". Reference Source - Microsoft. Archived from the original on Dec 10, 2017. Retrieved 2025-08-06.
  9. ^ Ki?ling, Kristian (2009). "Adding graphic elements to your scripts with Zenity and KDialog". Linux Magazine. Retrieved 2025-08-06.

Sources

[edit]
[edit]
尿酸低有什么危害 花哨是什么意思 29周岁属什么生肖 早餐吃什么有营养 捡什么废品最值钱
男人沉默了说明什么 锁骨窝疼可能是什么病 lot什么意思 第二性征是什么意思 锅烧是什么
大黄蜂是什么车 山楂什么时候成熟 请产假需要什么材料 子宫前位什么姿势易孕 1.16是什么星座
什么是节气 plt是什么 内疚是什么意思 囊肿是什么原因造成的 胰腺上长瘤意味着什么
龙利鱼是什么鱼hcv7jop9ns5r.cn 蛇胆疮是什么引起的hcv8jop3ns4r.cn 心脏搭桥是什么病hcv9jop3ns3r.cn 腮腺炎反复发作是什么原因hcv9jop1ns8r.cn 射手座的幸运色是什么qingzhougame.com
多囊什么意思hcv7jop4ns5r.cn 什么人不能吃玉米hcv9jop7ns2r.cn 秋田狐鱼钩适合钓什么鱼hcv7jop7ns0r.cn 喝酒上脸是什么原因hcv8jop3ns2r.cn 三千年前是什么朝代hcv8jop5ns7r.cn
nb是什么意思hcv9jop5ns4r.cn 吃什么最容易减肥hcv9jop4ns9r.cn 晚上放屁多是什么原因hcv9jop6ns5r.cn 葛根泡水有什么功效hcv8jop4ns9r.cn 巴西龟吃什么食物hcv7jop4ns6r.cn
乌龟一般吃什么hcv8jop1ns6r.cn 拔罐什么时候拔最好hcv9jop8ns0r.cn 肾阳虚的表现是什么sscsqa.com 狼吃什么hcv8jop5ns7r.cn 什么是卡路里gysmod.com
百度