powershell - 批量运行 PowerShell 命令
问题描述
我使用以下 PowerShell 命令运行 Perl 命令 (pp):
pp --% -u -x -g --link openssl.exe --link libpng16-16_.dll -o D:\Dati\file.exe -F Bleach="^(AT_|DB_)" "G:\Scripts work\script.pl"
在 PowerShell 中复制并粘贴它,它就像一个魅力。现在我想从一个 bat 文件中运行它。我试过了:
set CMD_LINE_ARGS="%*"
powershell -Command "{pp --% -u -x -g --link openssl.exe --link libpng16-16_.dll -o D:\Dati\file.exe -F Bleach="^(AT_^|DB_)" "G:\Scripts work\script.pl"}"
我试图逃离管道“|” 与`。我的 bat 已运行,没有错误,但我的脚本没有启动。任何想法?
解决方案
您需要批量转义特殊的 CMD 字符,以便它们被 PowerShell.exe 解析。一些字符包括"
, ^
。内部双引号可以双引号或反斜杠转义。命令字符需要用^
.
powershell.exe -Command "{pp --% -u -x -g --link openssl.exe --link libpng16-16_.dll -o D:\Dati\file.exe -F Bleach=\"^^(AT_^|DB_)\" \"G:\Scripts work\script.pl\"}"
推荐阅读
- php - 使用 jquery 和 ajax 使用 foreach 循环插入多个复选框
- html - 在缩放的 html 正文上使用画布
- python - 调整 sklearn.ensemble.GradientBoostingClassifier 中预测方法阈值的方法
- python - 带有嵌入式 Matplotlib 的 PyQt - 焦点问题
- ios - iOS - 无法构建,缺少标题(虽然存在于文件夹中)
- arrays - Swift - 如何编码超过 512 个字符的字符串?
- xcode - 如何在 Xcode 助手编辑器预览模式下从纵向旋转到横向
- flash - 制作一个空中俘虏运行时捆绑包(用于虚拟级别)
- swift - 试图链接 XCTest 目标的未定义符号
- c - scanf 用数组格式化多个特殊字符