2013-05-27 110 views

回答

8

以下为我工作:

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-Objectwhere?),因此不返回任何内容,也不执行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

希望这有助于。

+0

感谢您的提示。这并不能解释为什么'哪里'在PS中不显示任何输出。 – Ragesh

+0

@Ragesh我更新了解释的答案和一种方法来解决这个问题。如果你有问题,请告诉我。 – Bill

+2

您也可以使用cmd.exe运行它。像'cmd/c“calc'' –

相关问题