Powershell:始终生成null文件(Compare-Object的输出)此问题最受欢迎的答案涉及以下Windows PowerShell代码(编辑以修复错误):$file1 = Get-Content C:\temp\file1.txt
$file2 = Get-Content C:\temp\file2.txt
$Diff = Compare-Object $File1 $File2
$LeftSide = ($Diff | Where-Object {$_.SideIndicator -eq '<='}).InputObject $LeftSide | Set-Content C:\temp\file3.txt我总是得到一个零字节文件作为输出,即使我删除$ Diff行。为什么输出文件总是为null,如何修复?
2 回答
米琪卡哇伊
TA贡献1998条经验 获得超6个赞
也许不是
$LeftSide = ($Diff | Where-Object {$_.SideIndicator -eq '<='}).InputObject
PowerShell 2可能更适用于:
$LeftSide = $Diff | Where-Object {$_.SideIndicator -eq '<='} | Foreach-object { $_.InputObject }
- 2 回答
- 0 关注
- 850 浏览
添加回答
举报
0/150
提交
取消