为什么在 PowerShell 中运行时“where"命令不显示任何输出? [英] Why doesn't the 'where' command display any output when running in PowerShell?

查看:350
本文介绍了为什么在 PowerShell 中运行时“where"命令不显示任何输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在 CMD 中运行 where 时,我得到输出:

When I run where in CMD, I get output:

C:\Users\Ragesh> where calc
C:\Windows\System32\calc.exe

但在 PS 中也是一样:

But the same thing in 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.

So when you type where calc it is executing Where-Object calc (the alias of Where-Object is where and ?) and thus returns nothing, and not executing where.exe calc.

您可以使用 Get-Command(别名 gcm)cmdlet 代替 where.exe.这是一个示例函数,它使 Get-Command 功能与 where.exe 完全相同.如果你把它放在你的 PowerShell 配置文件它将始终在您的会话中可用.

You can use the Get-Command (alias gcm) cmdlet instead of where.exe. Here is an example function to make Get-Command function exactly like where.exe. If you put this in your PowerShell profile it will always be available in your session.

function which ($command) {
    Get-Command -Name $command -ErrorAction SilentlyContinue | 
        Select-Object -ExpandProperty Path -ErrorAction SilentlyContinue
}

以下链接可能有用-

相当于 Powershell 中的 *Nix 'which' 命令?

https://superuser.com/questions/34492/powershell-equivalent-to-unix-which-command

希望这会有所帮助.

这篇关于为什么在 PowerShell 中运行时“where"命令不显示任何输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆