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 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

AI Hentai Generator

AI Hentai Generator

AIヘンタイを無料で生成します。

ホットツール

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

SublimeText3 中国語版

SublimeText3 中国語版

中国語版、とても使いやすい

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強力な PHP 統合開発環境

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開発ツール

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)

CSS を使用して要素の背景の回転アニメーション効果を実現する方法 CSS を使用して要素の背景の回転アニメーション効果を実現する方法 Nov 21, 2023 am 09:05 AM

CSS を使用して要素の回転背景画像アニメーション効果を実装する方法 背景画像アニメーション効果は、Web ページの視覚的な魅力とユーザー エクスペリエンスを向上させることができます。この記事では、CSS を使用して要素の背景の回転アニメーション効果を実現する方法を紹介し、具体的なコード例を示します。まず、背景画像を用意します。太陽や扇風機など、好きな画像を使用できます。画像を「bg.png」という名前で保存します。次に、HTML ファイルを作成し、ファイルに div 要素を追加して、次のように設定します。

Linuxのmakeコマンドとは何ですか? Linuxのmakeコマンドとは何ですか? Mar 25, 2023 am 09:14 AM

linux make コマンドは、システム管理者やプログラマーによって最も頻繁に使用されるコマンドの 1 つです。また、「自動コンパイル マネージャー」も指します。「自動」とは、ファイルのタイムスタンプに基づいて新しいファイルを自動的に検出し、作業負荷を軽減できることを意味します。同時に、メイクファイル ファイルの内容を読み取ることで、大量のコンパイル作業を実行できます。

ページにジャンプするパラメータを含む PHP の POST メソッドの簡単な分析 ページにジャンプするパラメータを含む PHP の POST メソッドの簡単な分析 Mar 23, 2023 am 09:15 AM

PHP 開発者にとって、POST を使用してパラメータのあるページにジャンプすることは基本的なスキルです。 POST は HTTP でデータを送信する方法で、HTTP リクエストを通じてサーバーにデータを送信できます。ジャンプ ページはサーバー側でページを処理してジャンプします。実際の開発では、特定の機能上の目的を達成するために、パラメーターを指定して POST を使用してページにジャンプする必要があることがよくあります。

Pythonリクエストポストの使い方 Pythonリクエストポストの使い方 Apr 29, 2023 pm 04:52 PM

Python はブラウザーによるポスト リクエストの送信をシミュレートします importrequests 形式 request.postrequest.post(url,data,json,kwargs)#ポスト リクエストの形式 request.get(url,params,kwargs)#get リクエストと比較して、ポスト リクエストの送信パラメータは次のように分割されますForms ( x-www-form-urlencoded) json (application/json) データ パラメーターは、辞書形式と文字列形式をサポートしています。辞書形式は、 json.dumps() メソッドを使用して、データを有効な JSON 形式の文字列に変換します。このメソッドには、次のものが必要です

投稿が PHP で送信されたかどうかを確認する方法 投稿が PHP で送信されたかどうかを確認する方法 Mar 21, 2023 pm 07:12 PM

PHP は、インタラクティブで動的な Web アプリケーションの作成に使用できる、広く使用されているサーバー側スクリプト言語です。 PHP アプリケーションを開発する場合、通常、フォームを介して処理するためにユーザー入力データをサーバーに送信する必要があります。ただし、フォームデータがPHPで送信されたものであるかどうかを判断する必要がある場合があるので、この記事ではその判断方法を紹介します。

Java はどのようにして http リクエストを開始し、ポストを呼び出してインターフェースを取得するのでしょうか? Java はどのようにして http リクエストを開始し、ポストを呼び出してインターフェースを取得するのでしょうか? May 16, 2023 pm 07:53 PM

1. Java は post インターフェイスを呼び出します 1. Java に付属の URLConnection または HttpURLConnection を使用します 他の 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 コマンドはコマンド ライン引数などのターゲットを受け入れます。これらのターゲットは通常、「makefiles」という名前の特別なファイルに保存され、ファイルにはターゲットに対応する操作も含まれています。詳細については、Makefile の仕組みに関するこの一連の記事を参照してください。 make コマンドが初めて実行されるとき、makefile をスキャンしてターゲットとその依存関係を見つけます。これらの依存関係自体がターゲットである場合は、これらの依存関係のメイクファイルのスキャンを続けて依存関係を確立し、コンパイルします。主要な依存関係がコンパイルされると、次にメイン ターゲットがコンパイルされます (これは make コマンドを通じて渡されます)。ここで、ソース ファイルに変更を加えたと仮定すると、

See all articles