首页 数据库 mysql教程 make 2>&1

make 2>&1

Jun 07, 2016 pm 03:25 PM
amp background make post this

Background of this post: Recently, I always noticed that many guys can't distinguish the meaning among stdin, stdout, and stderr, especially, they always ask the same question as: what does 21 exactly mean? So, here I want to give a summar

Background of this post:

Recently, I always noticed that many guys can't distinguish the meaning among stdin, stdout, and stderr, especially, they always ask the same question as: what does "2>&1" exactly mean?

So, here I want to give a summary of this three things, and of course, I'd like to take this "2>&1" as an example.

-----------------------
Interpretation:

First of all, I want to give out the exact meaning of "2>&1":

2>&1:

0 is stdin. 1 is stdout. 2 is stderr
-------------
There's one way to remember this construct (maybe it is not entirely accurate):
-------------
First of all, 2>1 looks like a very good way to redirect stderr to stdout. but remember, it has a very harmful disadvantage: it may actually be interpreted as "redirect stderr to a file named 1".
-------------
& indicates that what follows is a file descriptor and not a filename. So the construct becomes: 2>&1.
-------------
>& is shell syntax for "fold a file descriptor into another", you can also interprete it as "it is the syntax to redirect a stream to another file descriptor"

So, now, have you got the meaning of what does "2>&1" exact mean? I think you do!

Yes, it's very easy to understand, but what's more, I want to go little deep into this topic.

-----------------------
Furthermore:

Following picture gives a very clear defination of what is stdin stdout and stderr:

#  In Linux everything is a file.
# Your hardware is also a file:
* 0 - Input - Keyboard (stdin)
* 1 - Output - Screen (stdout)
* 2 - Error - Screen (stderr)

make 2>&1# For standard output:

make 2>&1Clear enough?

If you still feel confused about this, you can view this page to find more infomation:
http://tldp.org/LDP/abs/html/io-redirection.html

-----------------------
Example:

Finally, I want to give you a example to end this entry(Try to understand it ^_^):

The output of a.out is the following, without the 'STDXXX: ' prefix.

STDERR: stderr output<br> STDOUT: more regular

./a.out 3>&1 1>&2 2>&3 3>&- | sed 's/e/E/g'<br> more regular<br> stderr output

  1. First save stdout as &3 (&1 is duped into 3).
  2. Next send stdout to stderr (&2 is duped into 1).
  3. Send stderr to &3 (stdout) (&3 is duped into 2).
  4. close &3 (&- is duped into 3)

-----------------------
Others:

If you want to know what's the difference between "cmd >file 2>&1" and "cmd >file 2>file", pls refer this post which written by r2007:
http://bbs.chinaunix.net/thread-764727-1-1.html

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您听不到任何人,如何修复音频
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解锁Myrise中的所有内容
4 周前 By 尊渡假赌尊渡假赌尊渡假赌

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

如何使用CSS实现元素的旋转背景图动画效果 如何使用CSS实现元素的旋转背景图动画效果 Nov 21, 2023 am 09:05 AM

如何使用CSS实现元素的旋转背景图动画效果背景图动画效果可以增加网页的视觉吸引力和用户体验。本文将介绍如何使用CSS实现元素的旋转背景图动画效果,并提供具体的代码示例。首先,我们需要准备一张背景图,可以是任何你喜欢的图片,例如一张太阳或者电风扇的图片。将该图片保存并命名为“bg.png”。接下来,创建一个HTML文件,并在文件中添加一个div元素,将其设置为

linux make命令是什么 linux make命令是什么 Mar 25, 2023 am 09:14 AM

linux make命令是系统管理员和程序员用的最频繁的命令之一,也是指一个“自动编译管理器”,其中“自动”是指它能够根据文件时间戳自动发现跟新过的文件而减少工作量,同时,他能通过读入makefile文件的内容来执行大量编译工作。

浅析php中POST方法带参数跳转页面 浅析php中POST方法带参数跳转页面 Mar 23, 2023 am 09:15 AM

对于PHP开发者来说,使用POST带参数跳转页面是一项基本技能。POST是HTTP中一种发送数据的方法,它可以通过HTTP请求向服务器提交数据,跳转页面则是在服务器端进行页面的处理和跳转。在实际开发中,我们经常需要使用POST带参数来跳转页面,以达到一定的功能目的。

php怎么判断post有没有提交 php怎么判断post有没有提交 Mar 21, 2023 pm 07:12 PM

PHP是一种广泛使用的服务器端脚本语言,它可以用于创建交互式和动态的Web应用程序。在开发PHP应用时,我们通常需要通过表单将用户输入数据提交给服务器端处理。然而,有时候我们需要在PHP中判断是否有表单数据被提交,这篇文章将介绍如何进行这样的判断。

python requests post如何使用 python requests post如何使用 Apr 29, 2023 pm 04:52 PM

python模拟浏览器发送post请求importrequests格式request.postrequest.post(url,data,json,kwargs)#post请求格式request.get(url,params,kwargs)#对比get请求发送post请求传参分为表单(x-www-form-urlencoded)json(application/json)data参数支持字典格式和字符串格式,字典格式用json.dumps()方法把data转换为合法的json格式字符串次方法需要

java如何发起http请求调用post与get接口 java如何发起http请求调用post与get接口 May 16, 2023 pm 07:53 PM

一、java调用post接口1、使用URLConnection或者HttpURLConnectionjava自带的,无需下载其他jar包URLConnection方式调用,如果接口响应码被服务端修改则无法接收到返回报文,只能当响应码正确时才能接收到返回publicstaticStringsendPost(Stringurl,Stringparam){OutputStreamWriterout=null;BufferedReaderin=null;StringBuilderresult=newSt

NGINX反向代理对HTML页面的POST请求返回405怎么解决 NGINX反向代理对HTML页面的POST请求返回405怎么解决 May 22, 2023 pm 07:49 PM

实现如下:server{listen80;listen443ssl;server_namenirvana.test-a.gogen;ssl_certificate/etc/nginx/ssl/nirvana.test-a.gogen.crt;ssl_certificate_key/etc/nginx/ssl/nirvana.test-a.gogen.key;proxy_connect_timeout600;proxy_read_timeout600;proxy_send_timeout600;c

linux下如何使用make命令 linux下如何使用make命令 May 15, 2023 pm 12:37 PM

make如何工作的对于不知道背后机理的人来说,make命令像命令行参数一样接收目标。这些目标通常存放在以“makefile”来命名的特殊文件中,同时文件也包含与目标相对应的操作。更多信息,阅读关于makefiles如何工作的系列文章。当make命令第一次执行时,它扫描makefile找到目标以及其依赖。如果这些依赖自身也是目标,继续为这些依赖扫描makefile建立其依赖关系,然后编译它们。一旦主依赖编译之后,然后就编译主目标(这是通过make命令传入的)。现在,假设你对某个源文件进行了修改,你

See all articles