1

我是powershell的新手,但我面临一个非常基本的问题。当我运行以下命令时,powershell 会抱怨。特殊字符似乎有问题:[*, =, &, <, >]. 任何想法我如何逃避它们?这是 powershell 版本 2。 [我正在使用 winexe 从 linux 机器上运行 powershell 命令。如果我复制粘贴 ps 命令,它似乎工作正常,但远程运行它会导致 powershell 抱怨。]

winexe "cmd /c echo . | powershell Set-ExecutionPolicy bypass -Force -Scope CurrentUser;C:\test.ps1  -name 'B*=&<+>%N' -extra_logging '0' "

dos charset 'CP850' 不可用 - 使用 ASCII 字符串开始: At line:1 char:106 + Set-ExecutionPolicy bypass -Force -Scope CurrentUser;C:\test.ps1 -lun <<<< 'B*= is missing the终结者:'。在 line:1 char:110 + Set-ExecutionPolicy bypass -Force -Scope CurrentUser;C:\test.ps1 -lun 'B*= <<<< + CategoryInfo : ParserError: (B*=:String) [], ParentContainsErro rRecordException + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString

该系统找不到指定的文件。该系统找不到指定的文件。

4

2 回答 2

3

问题不是powershell,而是常规的命令shell。对做什么做出合理的假设winexe,命令的相关部分是

cmd /c echo . | powershell Set-ExecutionPolicy bypass -Force -Scope CurrentUser;C:\test.ps1 -name 'B*=&<+>%N' -extra_logging '0'

其中包含一些由命令外壳解释的特殊字符。单引号中的内容不被视为被引用,因此您需要明确引用它们。只是为了让生活变得困难,因为您使用的是管道,所以字符被处理了两次,所以您需要双引号:

cmd /c echo . | powershell Set-ExecutionPolicy bypass -Force -Scope CurrentUser;C:\test.ps1 -name 'B*=^^^&^^^<+^^^>^%N' -extra_logging '0'

插入符号使命令 shell 从字面上获取以下字符。

或者,如果发生这种情况,它winexe会将提供给命令外壳的命令传递给命令外壳,而不是直接执行它,您可能需要三重引号,即每个特殊字符前有七个插入符号。

于 2013-10-02T05:23:12.400 回答
0

我可能是错的,但我相信它是倒撇号或坟墓符号,即`

于 2013-10-02T04:05:41.030 回答