windows - Powershell - 在 CMD 上运行命令 - 通配符抛出错误
问题描述
我正在尝试通过 CMD 运行以下 Powershell 命令:
powershell -command "Get-WmiObject Win32_Process | Where-Object {$_.CommandLine -like \"*C:\Windows\Test*\" } | Select-Object ProcessName, CommandLine"
上面的命令直接在 Powershell 上运行良好,但只有在我尝试在 CMD 上运行时才会出现问题。在我的测试中,我发现 * 符号无法正确处理,我试图在符号前放一个反斜杠进行测试,但这并没有成功。有没有办法让它与 CMD 中的 * 符号一起使用?
编辑: 此命令用于查看包含命令行 C:\Windows\Test 的进程
解决方案
更简单,不需要 PowerShell:
wmic process where "commandline like '%c:\\windows\\test%'" get name, commandline
为了完整起见,为了正确地保持主题,使用 cmd.exe 中的 PowerShell,我会更像这样:
powershell -noprofile "get-ciminstance -query \"select * from win32_process where commandline like '%c:\\windows\\test%'\" | select-object -property processname, commandline"
推荐阅读
- hyperledger-fabric - 如何配置对等节点连接到 7050 以外的另一个端口上的排序服务?
- reactjs - React ref.current 在 componentDidMount 中仅在酶测试中为空,而不是实时为空
- scala - 如果列表中不存在,则附加 xml 节点
- android - 从我的收藏中读取和写入文档时,firestore 规则不起作用
- java - 如何获取特定行的 Java 程序的堆栈跟踪
- android - 以编程方式设置时,ImageView 总是返回空白
- jquery - div进入视口后如何添加类,div离开视口后如何删除类?
- firebase - Firebase OTP 仅适用于某些设备 - Swift 4
- r - R中的部分或模糊匹配
- angular - 如何在 Angular 6+ CLI 中使用 Handlebars.js?