gpt4 book ai didi

powershell - 如何通过 PowerShell 中的命令行将原始字符串传递给命令?

转载 作者:行者123 更新时间:2023-12-04 11:39:28 24 4
gpt4 key购买 nike

我们的 IT 部门正在转向 Windows 8,每个人都开始使用 PowerShell 作为他们的默认 Windows 命令行环境,而不是 cmd.exe .

不幸的是,PowerShell 会评估您在其中键入的内容,并且很难将原始命令行参数传递给程序。

例如我有一个程序 inventory.exe它需要一个特殊的字符串来格式化其输出。我无法在 PowerShell 中传递这个特殊字符串,因为我收到一个神秘错误:

PS C:\Users\Administrator> inventory.exe 'inventory "," date "," owner'
inventory.exe error: No comma allowed

我假设 PowerShell 评估了 'inventory "," date "," owner'字符串以某种方式传递给 inventory.exe程序结果它打印了一个错误。

该程序在 cmd.exe 中运行正常:
C:\Documents and Settings\boda> inventory.exe 'inventory "," date "," owner'
... (the output that I expect) ...

如果我输入诸如 % 之类的字符,情况会更糟。 , $在 PowerShell 中。

有谁知道如何将原始字符串传递给 PowerShell 中的命令?

最佳答案

如果您使用的是 Powershell v3.0,则有一种新语法可以使 Powershell 避免对参数进行任何额外的解析。就像是:

inventory.exe --% 'inventory', 'date', 'owner'

还有这里提到的其他方法: http://blogs.technet.com/b/josebda/archive/2012/03/03/using-windows-powershell-to-run-old-command-line-tools-and-their-weirdest-parameters.aspx

关于powershell - 如何通过 PowerShell 中的命令行将原始字符串传递给命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18187020/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com