2013-07-29 6 views
16

Ich habe das folgende Skript:Was bedeutet 2> & 1 in Powershell Mittlere

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

Ich bin gespannt, was 2>&1 ist; oder, was es darstellt. Ich weiß nicht, wie es heißt, sonst würde ich nachsehen.

+3

möglich Duplikat [In der Schale, was ist "2> & 1"?] (Http://stackoverflow.com/questions/818255/in-the-shell-what-is-21) – x0n

+0

'2> & 1' sieht für mich wie eine IO-Weiterleitung aus ... aber ich bin mit Powershell nicht so vertraut. –

+0

@ x0n antwortet, dass das für Windows gilt? Es sieht für mich wie Unix aus; Gibt es einen Unterschied? – BlackHatSamurai

Antwort

16

Es Standardfehler umleitet (der 2) an der gleichen Stelle wie die Standardausgabe (die 1)

20

Die Dokumente sind deine Freunde. PS> man about_Redirection von

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

Vielen Dank für die Antwort, aber wie ich in meinem Beitrag gesagt habe, wie kann ich nach etwas suchen, wenn ich nicht weiß, was es ist. Wenn ich wüsste, dass es sich um eine Weiterleitung handelt, könnte ich Ihre Antwort verwenden und hätte nicht gepostet. – BlackHatSamurai

+9

Sie können das Hilfesystem mit Platzhaltern durchsuchen. 'Get-Help '* & 1 *' zeigt auf das obige Thema. – latkin

+0

Das wusste ich nicht. Vielen Dank :) – BlackHatSamurai