当我where
在CMD中运行时,我得到输出:
C:\Users\Ragesh> where calc
C:\Windows\System32\calc.exe
Run Code Online (Sandbox Code Playgroud)
但在PS中同样的事情:
PS C:\data\code> where calc
PS C:\data\code>
Run Code Online (Sandbox Code Playgroud)
输出在哪里?!
Bil*_*ill 13
以下对我有用:
PS C:\Users\Bill> where.exe calc
C:\Windows\System32\calc.exe
Run Code Online (Sandbox Code Playgroud)
键入where
PS时,它与执行不同where.exe
PS C:\Users\Bill> where <press ENTER>
cmdlet Where-Object at command pipeline position 1
Supply values for the following parameters:
Property:
Run Code Online (Sandbox Code Playgroud)
因此,当您键入where calc
它时,它正在执行Where-Object calc
(Where-Object
is where
和别名?
),因此不会返回任何内容,也不会执行where.exe calc
.
您可以使用Get-Command
(别名gcm
)cmdlet而不是where.exe
.这是一个使Get-Command
函数完全像的示例函数where.exe
.如果将其放在PowerShell配置文件中,它将始终在您的会话中可用.
function which ($command) {
Get-Command -Name $command -ErrorAction SilentlyContinue |
Select-Object -ExpandProperty Path -ErrorAction SilentlyContinue
}
Run Code Online (Sandbox Code Playgroud)
以下链接可能有用 -
https://superuser.com/questions/34492/powershell-equivalent-to-unix-which-command
希望这可以帮助.
归档时间: |
|
查看次数: |
819 次 |
最近记录: |