首页 > 解决方案 > 批量运行 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 已运行,没有错误,但我的脚本没有启动。任何想法?

标签: powershellbatch-file

解决方案


您需要批量转义特殊的 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\"}"

推荐阅读