2013-07-29 2 views
16

У меня есть следующий сценарий:Что 2> & 1 Mean в PowerShell

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

Мне интересно, что 2>&1 есть; или, что он представляет. Я не знаю, как это называется, иначе я бы посмотрел.

+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

перенаправляет стандартные ошибки (2) в том же месте, что и стандартный вывод (1)

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

Смежные вопросы