Powershell:与>;之间的区别;?
在PowerShell中,Powershell:与>;之间的区别;?,powershell,Powershell,在PowerShell中,|和之间有什么区别 dir | CLIP #move data to clipboard dir > CLIP #not moving, creating file CLIP (no extension) 我是否可以假定|将当前结果移动到管道中的下一个块,并将数据保存到文件中 还有其他区别吗?你是对的: |将对象沿成功/输出流向下输送 在将对象从一个cmdlet传递到另一个cmdlet时,您不希望接收cmdlet接收错误、警告、调试消息或详细消息以及它设计用
|
和
之间有什么区别
dir | CLIP #move data to clipboard
dir > CLIP #not moving, creating file CLIP (no extension)
我是否可以假定|
将当前结果移动到管道中的下一个块,并
将数据保存到文件中
还有其他区别吗?你是对的:
将对象沿成功/输出流向下输送|
将输出发送到指定的文件
将输出附加到指定的文件>
|
和
是两件不同的事情
是一种所谓的重定向操作符
重定向操作符将流的输出重定向到文件或另一个流。管道操作符通过管道将cmdlet或函数的返回对象传递到下一个对象(或管道的末端)。当管道使用其属性泵送整个对象时,重定向管道仅用于输出。我们可以用一个简单的例子来说明这一点:
#Get the first process in the process list and pipe it to `Set-Content`
PS> (Get-Process)[0] | Set-Content D:\test.test
PS> Get-Content D:/test.test
输出
System.Diagnostics.Process(AdAppMgrSvc)
尝试将对象转换为字符串
输出
第三个示例将显示管道操作符的功能:
PS> (Get-Process)[0] | select * | Set-Content D:\test.test
PS> Get-Content D:/test.test
这将输出一个包含所有进程属性的哈希表:
重定向操作符
还将输出转换为字符串,而管道|
保持对象的原样
Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName
------- ------ ----- ----- ------ -- -- -----------
420 25 6200 7512 3536 0 AdAppMgrSvc
PS> (Get-Process)[0] | select * | Set-Content D:\test.test
PS> Get-Content D:/test.test
@{Name=AdAppMgrSvc; Id=3536; PriorityClass=; FileVersion=; HandleCount=420; WorkingSet=9519104; PagedMemorySize=6045696; PrivateMemorySize=6045696; VirtualMemorySize=110989312; TotalProcessorTime=; SI=0; Handles=420; VM=110989312; WS=9519104; PM=6045696; NPM=25128; Path=; Company=; CPU=; ProductVersion=; Description=; Product=; __NounName=Process; BasePriority=8; ExitCode=; HasExited=; ExitTime=; Handle=; SafeHandle=; MachineName=.; MainWindowHandle=0; MainWindowTitle=; MainModule=; MaxWorkingSet=; MinWorkingSet=; Modules=; NonpagedSystemMemorySize=25128; NonpagedSystemMemorySize64=25128; PagedMemorySize64=6045696; PagedSystemMemorySize=236160; PagedSystemMemorySize64=236160; PeakPagedMemorySize=7028736; PeakPagedMemorySize64=7028736; PeakWorkingSet=19673088; PeakWorkingSet64=19673088; PeakVirtualMemorySize=135786496; PeakVirtualMemorySize64=135786496; PriorityBoostEnabled=; PrivateMemorySize64=6045696; PrivilegedProcessorTime=; ProcessName=AdAppMgrSvc; ProcessorAffinity=; Responding=True; SessionId=0; StartInfo=System.Diagnostics.ProcessStartInfo; StartTime=; SynchronizingObject=; Threads=System.Diagnostics.ProcessThreadCollection; UserProcessorTime=; VirtualMemorySize64=110989312; EnableRaisingEvents=False; StandardInput=; StandardOutput=; StandardError=; WorkingSet64=9519104; Site=; Container=}