windows - 如何使用值中的与号将字符串从cmd传递到powershell?
问题描述
在 Windows CMD 中,我想运行一个 powershell 脚本并传递字符串参数,这些参数在参数中包含引号和 & 符号。
U:\Desktop>PowerShell .\post "http://domain/api/app?pLanguage=en-US\"&\"pCompanyID=816" "{\"Message\":\"test message - please ignore\"}"
The string is missing the terminator: ".
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : TerminatorExpectedAtEndOfString
'\"pCompanyID=816"' is not recognized as an internal or external command,
operable program or batch file.
我该如何解决这个问题?
解决方案
来自本网站上的另一个问题 -如何在命令行 powershell 参数中转义 & 符号、分号和花括号?
将命令行字符串用嵌套的双引号和单引号括起来——例如“'[somestring]'”。
在您的具体情况下:
C:> powershell .\post "'http://domain/api/app?pLanguage=en-US&pCompanyID=816'" "'{\"Message\":\"test message - please ignore\"}'"
推荐阅读
- reactjs - 在页面组件的 getInitialProps 中通过 fetch 在接收到的页面之间传递数据
- moment-timezone - 如何清除与时刻时区对象关联的时区
- arm - OpenOCD 执行 MI 命令失败:-target-select remote localhost:3333
- c# - 有没有办法使用 Roslyn 中的 Compilation 对象从引用的程序集中获取程序集级属性?
- python - Python - 很难理解这个递归代码示例
- tsql - 是否有使用 FIFO 分配查询发票和接收的 SQL 语句
- javascript - 如何使用 ChartJS 获取一组 Date 对象并根据一天中的时间显示频率
- scala - 读取文件,控制台没有输出(intellij)
- python - ValueError:密集层的输入0与层不兼容::预期的min_ndim = 2,发现ndim = 1。收到的完整形状:[无]
- javascript - createStripeCharge gcloud Javascript函数错误未定义问题