`

标准输出与标准错误输出

阅读更多

What's   the   difference   between   the   two:   System.err.   and  
  System.out?   When   should   we   use   System.err?  
  Answer   1:   System.out   leads   the   output   to   the   standard   output   stream   (normally  
  mapped   to   your   console   screen),   System.err   leads   the   output   to   the   standard   error  
  stream   (by   default   the   console,   too).  
  The   standard   output   should   be   used   for   regular   program   output,   the   standard   error  
  for   error   messages.   If   you   start   your   console   program   regularly   both   message   types  
  will   appear   on   your   screen.  
  But   you   may   redirect   both   streams   to   different   destinations   (e.g.   files),   e.g.   if   you  
  want   to   create   an   error   log   file   where   you   don't   want   to   be   the   regular   output   in.  
  On   an   UNIX   you   may   redirect   the   output   as   follows:  
  java   yourprog.class   >output.log   2>error.log  
  this   causes   your   regular   output   (using   System.out)   to   be   stored   in  
  output.log   and   your   error   messages   (using   System.err)   to   be   stored   in   error.log  
  Answer   2:   System.err   is   a   "special"   pipe   that   usually   is   directed   to   the   standard  
  console.   You   can   redirect   the   System.out   with   the   normal   pipe   control   (|   or   >),   but  
  System.err   no.   If   you   want   to   put  
  both   the   "normal"   output   and   the   "error"   output   to   a   file   you   must   use   the   special  
  redirect   2>.  
  This   allow   you   to   send   normal   messages   into   a   file   or   in   the   /null  
  black   hole,   but   still   receive   the   error   messages   on   the   console.

分享到:
评论

相关推荐

    标准输入标准输出标准错误输出的源头分析

    程序员都知道一个程序启动后就伴随着该程序而来的3个I/O句柄,标准输入,标准输出和标准错误输出。为什么是这样呢?教材知识告诉我们现象,但从来没有回答为什么。我不知道为什么要刻意或无意的不提这个“为什么”。...

    易语言曙光标准输入输出模块测试源码,易语言重定向输入输出模块

    易语言曙光重定向输出模块源码,曙光重定向输出模块,曙光_初始化标准输入输出,曙光_标准输入,曙光_检查标准输入,曙光_标准输出,曙光_标准错误输出,GetStdHandle,ReadFile_,PeekNamedPipe,WriteFile_,是否在运行,终止,...

    Linux标准输入、输出和重定向

    标准输出文件(stdout)和标准错误输出文件(stderr),这两个文件都对应终端的屏幕。进程将从标准输入文件中得到输入数据,将正常输出数据输出到标准输出文件,而将错误信息送到标准错误文件中。

    操作系统实验报告-实验四.docx

    >/dev/null 2> /dev/null 标准输出与标准错误输出都会被丢弃*/ // 0 1 2 标准输入 标准输出 错误输出 // > 将信息放到该文件null中 end=times(&t_end); time_print("elapsed",end-start); puts("parent times"); ...

    Linux base shell重定向详解

    一、标准输入,标准输出与标准错误输出 在linux shell执行命令时,每个进程都和三个打开的文件相联系,并使用文件描述符来引用这些文件。由于文件描述符不容易记忆,shell同时也给出了相应的文件名: 文件 文件...

    seliencepuppet#linux#13.管道和标准输入输出1

    如果想要正常输出和错误信息都不显示,则要把标准输出和标准错误都重定向到/dev/null, 例如:还有一种做法是将错误重定向到标准输出,然后再重定向到 /dev

    输出端子.doc

     AV端子:也称AV接口,通常都是成对的白色的音频接口和黄色的视频接口,它通常采用RCA(俗称莲花头)进行连接,使用时只需要将带莲花头的标准AV 线缆与相应接口连接起来即可。AV接口实现了音频和视频的分离传输,这...

    process:用于捕获流程标准输出和错误的库

    Process 是一个用于运行外部进程并捕获其标准输出和错误的库。 安装库 (Linux) 获取源码: git clone https://github.com/sabel83/process && cd process 创建构建目录: mkdir bin && bin 生成 Makefile: ...

    pad-stdio:填充标准输出和标准错误

    Pad-stdio 填充标准输出和标准错误当您不直接控制输出时,对CLI工具特别有用。安装$ npm install pad-stdio用法import { padStdout } from 'pad-stdio' ;padStdout ( ' ' ) ; // Start paddingconsole . log ( 'foo'...

    vim编辑器中掌握输入输出重定向与管道命令的应用

    重定向就是不使用系统的标准输入端口、标准输出端口或标准错误端口,而进行重新的指定,所以重定向分为输入重定向、输出重定向和错误重定向。通常情况下,重定向到一个文件。在shell中,要实现重定向主要依靠重定向...

    Linux操作之输入输出重定向和管道

     Unix下使用标准输入stdin和标准输出stdout,来表示每个命令的输入和输出,还使用一个标准错误输出stderr用于输出错误信息。这三个标准输入输出系统缺省与控制终端设备相联系在一起的。因此,在标准情况下,每个...

    详解python的几种标准输出重定向方式

    是基于Python2.7版本,介绍常见的几种标准输出(stdout)重定向方式。显然,这些方式也适用于标准错误重定向。学习python的小伙伴们可以参考借鉴。

    matlab中pca输出参数对比解析

    matlab中pca输出参数对比解析,[coeff,score,latent] = pca( );标准化数据输入到pca与pca输出之后标准化对比,score与coeff对比

    protobuf根据DebugString输出字串反解pb对象的实例(C++)

    仔细观察发现输出并不是标准json格式,也就是说基于json→pb的路子是行不通的了。难道就没有其他办法了吗?答案是有的,本实例就提供了转换方法。使用过程中如果有什么问题可以私信博主,我看到后会第一时间解答。

    神奇的shell命令行输入与输出功能介绍

    标准输出文件(stdout)和标准错误输出文件(stderr),这两个文件都对应终端的屏幕。进程将从标准输入文件中得到输入数据,将正常输出数据输出到标准输出文件,而将错误信息送到标准错误文件中。 我们以cat命令为例...

    Linux输入输出重定向详细使用说明

    1、Linux标准输入输出 Linux标准输入、输出设备主要...标准错误输出 2> 2>> 注:其中一个>表示:覆盖原文件中的内容;如果文件不存在,就创建文件;如果文件存在,就将其清空;一般我们备份清理日志文件的时候 两个

    输入输出重定向

    当执行Linux程序命令时,会使用到三个东西:**标准输入**(standin),**标准输出**(standout),**标准错误**(standerr) 其对应的描述符如下表: 类别 文件描述符 标准输出 0 标准输入 1 标准错误 2 ...

    Python 从subprocess运行的子进程中实时获取输出的例子

    对此,subprocess模块也提供了相应的参数,能够将子程序的标准输出和标准错误输出返回给主程序。 下面,我们就通过一个例子来说明这个功能。首先,我们需要一个用于模拟标准输出和标准错误输出的“子程序”——...

    EasyProcessStreams:简化过程的标准输出,输入和错误

    简化了过程的标准输出,输入和错误。 目的 System.Diagnostics.Process API的主要但不太明显的问题之一是死锁问题。 这三个过程流(输入,输出和错误)在它们可以缓冲多少内容方面都是有限的。 如果内部缓冲区已满,...

Global site tag (gtag.js) - Google Analytics