2013-07-29 15 views
16

Mam następujący scenariusz:Co 2> & 1 oznacza w PowerShell

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

jestem ciekaw co 2>&1 jest; lub, co on reprezentuje. Nie wiem, jak się nazywa, inaczej, sprawdziłbym to.

+3

możliwym duplikatu [w powłoce, co to jest "2> & 1"?] (Http://stackoverflow.com/questions/818255/in-the-shell-what-is-21) – x0n

+0

'2> & 1' wygląda dla mnie na przekierowanie IO ... ale nie jestem zaznajomiony z Power Shell. –

+0

@ x0n ma odpowiedź, która dotyczy systemu Windows? Dla mnie wygląda na Unixa; czy jest jakaś różnica? – BlackHatSamurai

Odpowiedz

16

To przekierowuje błąd standardowy (The 2) na tym samym miejscu co standardowe wyjście (z 1)

20

Docs są twoi przyjaciele. Od 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

Dziękuję za odpowiedź, ale jak powiedziałem w swoim poście, jak mogę coś wyszukać, jeśli nie wiem, co to jest. Gdybym wiedział, że to przekierowanie, mógłbym użyć twojej odpowiedzi i nie musiałbym publikować. – BlackHatSamurai

+9

Możesz przeszukiwać system pomocy za pomocą symboli wieloznacznych. 'Get-Help '* i 1 *" wskazuje na powyższy temat. – latkin

+0

Tego nie wiedziałem. Dziękuję Ci :) – BlackHatSamurai