4
当我在CMD运行where
,我得到的输出:在PowerShell中运行时,为什么'where'命令不显示任何输出?
C:\Users\Ragesh> where calc
C:\Windows\System32\calc.exe
但在PS同样的事情:
PS C:\data\code> where calc
PS C:\data\code>
哪里的输出去?
当我在CMD运行where
,我得到的输出:在PowerShell中运行时,为什么'where'命令不显示任何输出?
C:\Users\Ragesh> where calc
C:\Windows\System32\calc.exe
但在PS同样的事情:
PS C:\data\code> where calc
PS C:\data\code>
哪里的输出去?
以下为我工作:
PS C:\Users\Bill> where.exe calc
C:\Windows\System32\calc.exe
当您在PS键入where
,它不等同于执行where.exe
PS C:\Users\Bill> where <press ENTER>
cmdlet Where-Object at command pipeline position 1
Supply values for the following parameters:
Property:
所以,当你键入where calc
正在执行Where-Object calc
(别名的Where-Object
是where
和?
),因此不返回任何内容,也不执行where.exe calc
。
您可以使用Get-Command
(别名为gcm
)cmdlet替代where.exe
。以下是使Get-Command
功能与where.exe
完全相同的示例功能。如果您将其放在您的PowerShell profile中,它将始终在您的会话中可用。
function which ($command) {
Get-Command -Name $command -ErrorAction SilentlyContinue |
Select-Object -ExpandProperty Path -ErrorAction SilentlyContinue
}
以下链接可能是有用的 -
Equivalent of *Nix 'which' command in Powershell?
https://superuser.com/questions/34492/powershell-equivalent-to-unix-which-command
希望这有助于。
感谢您的提示。这并不能解释为什么'哪里'在PS中不显示任何输出。 – Ragesh
@Ragesh我更新了解释的答案和一种方法来解决这个问题。如果你有问题,请告诉我。 – Bill
您也可以使用cmd.exe运行它。像'cmd/c“calc'' –