2016-01-29 104 views
1

当我运行此命令:'>>'在PowerShell中做什么?

Get-Content generated\no_animate.css >> generated\all.css 

它复制第一文件内容到第二个文件。 >>符号的官方术语是什么,我可以在哪里找到关于这个和其他的更多信息?

不出所料,在Google搜索>>并不是非常有用的信息。

+3

在PowerShell提示符类型:***获取帮助about_Redirection *** – EBGreen

+0

感谢,我试过命令,并且它失败了:Get-Help:Get-Help在这个会话的帮助文件中找不到about_Redirection。要下载更新的帮助 主题,请键入:“更新 - 帮助”。要获得在线帮助,请在TechNet库中搜索帮助主题 http://go.microsoft.com/fwlink/?LinkID = 107116.'尝试更新并由于我的公司代理失败后,我发现通过搜索'about_Redirection'找到MSDN上的信息。 – 4imble

+0

您使用的是什么版本的PowerShell? – EBGreen

回答

1

感谢EBGreen,我找到了这些信息。

https://technet.microsoft.com/en-us/library/hh847746.aspx

主题 about_Redirection

简短说明 说明如何输出的Windows PowerShell重定向到文本文件。

详细描述 默认情况下,Windows PowerShell将其命令输出发送到Windows PowerShell控制台。但是,您可以将输出指向文本 文件,并且可以将错误输出重定向到常规输出流。

You can use the following methods to redirect output: 

    - Use the Out-File cmdlet, which sends command output to a text file. 
     Typically, you use the Out-File cmdlet when you need to use its 
     parameters, such as the Encoding, Force, Width, or NoClobber 
     parameters. 

    - Use the Tee-Object cmdlet, which sends command output to a text file 
     and then sends it to the pipeline. 

    - Use the Windows PowerShell redirection operators. 

的Windows PowerShell重定向操作符 重定向操作符让你发送特定类型的输出 的文件和文件到成功输出流。

The Windows PowerShell redirection operators use the following characters 
    to represent each output type: 
    * All output 
    1 Success output 
    2 Errors 
    3 Warning messages 
    4 Verbose output 
    5 Debug messages 

      NOTE: The All (*), Warning (3), Verbose (4) and Debug (5) redirection operators were introduced 
         in Windows PowerShell 3.0. They do not work in earlier versions of Windows PowerShell. 

    The Windows PowerShell redirection operators are as follows. 
    Operator Description    Example 
    -------- ----------------------  ------------------------------ 
    >   Sends output to the  Get-Process > Process.txt 
      specified file. 

    >>  Appends the output to  dir *.ps1 >> Scripts.txt 
      the contents of the 
      specified file. 

    2>  Sends errors to the  Get-Process none 2> Errors.txt 
      specified file. 

    2>>  Appends errors to   Get-Process none 2>> Save-Errors.txt 
      the contents of the 
      specified file. 

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

    3>  Sends warnings to the  Write-Warning "Test!" 3> Warnings.txt 
      specified file. 

    3>>  Appends warnings to  Write-Warning "Test!" 3>> Save-Warnings.txt 
      the contents of the 
      specified file. 

    3>&1  Sends warnings (3) and  function Test-Warning 
      success output (1)   { Get-Process PowerShell; 
      to the success    Write-Warning "Test!" } 
      output stream.    Test-Warning 3>&1 

    4>  Sends verbose output to Import-Module * -Verbose 4> Verbose.txt 
      the specified file. 

    4>>  Appends verbose output  Import-Module * -Verbose 4>> Save-Verbose.txt 
      to the contents of the 
      specified file. 

    4>&1  Sends verbose output (4) Import-Module * -Verbose 4>&1 
      and success output (1)  
      to the success output 
      stream.    

    5>  Sends debug messages to Write-Debug "Starting" 5> Debug.txt 
      the specified file. 

    5>>  Appends debug messages  Write-Debug "Saving" 5>> Save-Debug.txt 
      to the contents of the 
      specified file. 

    5>&1  Sends debug messages (5) function Test-Debug 
      and success output (1)  { Get-Process PowerShell 
      to the success output  Write-Debug "PS" } 
      stream.     Test-Debug 5>&1 

    *>  Sends all output types  function Test-Output 
      to the specified file.  { Get-Process PowerShell, none 
             Write-Warning "Test!" 
    *>>  Appends all output types  Write-Verbose "Test Verbose" 
      to the contents of the  Write-Debug "Test Debug" } 
      specified file.    
             Test-Output *> Test-Output.txt 
    *>&1  Sends all output types  Test-Output *>> Test-Output.txt 
      (*) to the success output Test-Output *>&1  
      stream.  


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. 


To force the redirection of content to a read-only, hidden, or system file, 
use the Out-File cmdlet with its Force parameter. When you are writing to 
files, the redirection operators use Unicode encoding. If the file has a 
different encoding, the output might not be formatted correctly. To 
redirect content to non-Unicode files, use the Out-File cmdlet with its 
Encoding parameter. 

另请参阅 出文件 三通对象 about_Operators about_Command_Syntax about_Path_Syntax

+0

使用'>>'附加到文件在很多(大多数?)shell中很常见。它也可以在[Windows命令提示符](https://technet.microsoft.com/en-us/library/bb490982.aspx)以及bash和其他unix shell中运行。 – briantist

+0

很高兴知道,我一定会牢记这一点。 – 4imble