首頁 資料庫 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脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++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檔案的內容來執行大量編譯工作。

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格式字串次方法需要

淺析php中POST方法帶參數跳轉頁面 淺析php中POST方法帶參數跳轉頁面 Mar 23, 2023 am 09:15 AM

對於PHP開發者來說,使用POST帶參數跳轉頁面是一項基本技能。 POST是HTTP中一種發送資料的方法,它可以透過HTTP請求向伺服器提交數據,跳轉頁面則是在伺服器端進行頁面的處理和跳轉。在實際開發中,我們經常需要使用POST帶參數來跳轉頁面,以達到一定的功能目的。

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

php怎麼判斷post有沒有提交 php怎麼判斷post有沒有提交 Mar 21, 2023 pm 07:12 PM

PHP是一種廣泛使用的伺服器端腳本語言,它可以用於建立互動式和動態的網路應用程式。在開發PHP應用程式時,我們通常需要透過表單將使用者輸入資料提交給伺服器端處理。然而,有時候我們需要在PHP中判斷是否有表單資料被提交,這篇文章將介紹如何進行這樣的判斷。

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/test-a.gogen.crt;ssl_certificate_key/etc/nginx/ssl/nirvana.testssl/ .key;proxy_connect_timeout600;proxy_read_timeout600;proxy_send_timeout600;c

PHP跳轉頁面並攜帶POST資料的實作方法 PHP跳轉頁面並攜帶POST資料的實作方法 Mar 22, 2024 am 10:42 AM

PHP是一種廣泛應用於網站開發的程式語言,而頁面跳躍並攜帶POST資料是在網站開發中常見的需求。本文將介紹如何實現PHP頁面跳轉並攜帶POST數據,包括具體的程式碼範例。在PHP中,頁面跳躍一般透過header函數實現。如果需要在跳轉過程中攜帶POST數據,可以透過以下步驟完成:首先,建立一個包含表單的頁面,使用者在該頁面填寫資訊並點擊提交按鈕。在表單的acti

See all articles