2013-07-29 2 views
16
にどういう意味

I持って次のスクリプト:私は2>&1が何であるかについて興味2>&1は、PowerShellの

if($timeout -ne $null) 
{ 
    & $var$timeout 2>&1 > $logDir\$logName 
} 
else 
{ 
    & $var2>&1 > $logDir\$logName 
} 

。またはそれが表すもの私はそれが何と呼ばれているのか分からない、そうでなければ、私はそれを調べるだろう。

+3

可能重複から[シェルで、 "2>&1" は何ですか?](http://stackoverflow.com/questions/818255/in-the-shell-what-is-21) – x0n

+0

'2>&1'は私のIOリダイレクトのように見えますが、私はpowershellをよく知っているわけではありません。 –

+0

@ x0nはWindowsに適用される回答ですか?私にとってUnixのように見えます。何か違いはありますか? – BlackHatSamurai

答えて

16

それは標準出力(1)と同じ場所に標準誤差(2)をリダイレクトする

20

ドキュメントはあなたの友達です。 PS> man about_Redirection

The Windows PowerShell redirection operators are as follows. 

Operator Description    Example 
-------- ----------------------  ------------------------------ 
<snip> 

2>&1  Sends errors (2) and  Get-Process none, Powershell 2>&1 
      success output (1) 
      to the success 
      output stream. 

<snip> 

The syntax of the redirection operators is as follows: 

    <input> <operator> [<path>\]<file> 

If the specified file already exists, the redirection operators that do not 
append data (> and n>) overwrite the current contents of the file without 
warning. However, if the file is a read-only, hidden, or system file, the 
redirection fails. The append redirection operators (>> and n>>) do not 
write to a read-only file, but they append content to a system or hidden 
file. 
+3

答えをありがとう、私は私の記事で言ったように、私はそれが何であるかわからない場合、どのように私は何かを検索することができます。それがリダイレクトであることが分かっていれば、私はあなたの答えを使用することができ、投稿する必要はありませんでした。 – BlackHatSamurai

+9

ヘルプシステムをワイルドカードで検索できます。 'Get-Help '*&1 *' 'は上記のトピックを指します。 – latkin

+0

私は知らなかった。ありがとうございました :) – BlackHatSamurai

関連する問題