Powershell 将参数传递给外部命令-停止分析

Powershell 将参数传递给外部命令-停止分析,powershell,Powershell,我是PowerShell新手,尝试在调用外部cmd时停止解析。示例代码: $Exe = "C:\Program Files\Test\keygen.exe" # Execute command with arguments $Exe --% "-Z" 我认为停止解析器是正确的,-->会返回错误“the'--'运算符只对数字有效。操作数是“System.String” 这里怎么了?您将命令定义为字符串。PowerShell的默认行为是回显字符串并执行裸字: PS C:\> ping.exe 12

我是PowerShell新手,尝试在调用外部cmd时停止解析。示例代码:

$Exe = "C:\Program Files\Test\keygen.exe"
# Execute command with arguments
$Exe --% "-Z"
我认为停止解析器是正确的,
-->
会返回错误“the'--'运算符只对数字有效。操作数是“System.String”


这里怎么了?

您将命令定义为字符串。PowerShell的默认行为是回显字符串并执行裸字:

PS C:\> ping.exe 127.0.0.1 Pinging 127.0.0.1 with 32 bytes of data: Reply from 127.0.0.1: bytes=32 time<1ms TTL=128 Reply from 127.0.0.1: bytes=32 time<1ms TTL=128 Reply from 127.0.0.1: bytes=32 time<1ms TTL=128 Reply from 127.0.0.1: bytes=32 time<1ms TTL=128 Ping statistics for 127.0.0.1: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 0ms, Average = 0ms PS C:\> $exe = 'ping.exe' PS C:\> $exe ping.exe PS C:\> $exe 127.0.0.1 At line:1 char:6 + $exe 127.0.0.1 + ~~~~~~~~~ Unexpected token '127.0.0.1' in expression or statement. + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : UnexpectedToken
你忘了
&
@PetSerAl谢谢。现在正在工作:) PS C:\> & $exe 127.0.0.1 Pinging 127.0.0.1 with 32 bytes of data: Reply from 127.0.0.1: bytes=32 time<1ms TTL=128 Reply from 127.0.0.1: bytes=32 time<1ms TTL=128 Reply from 127.0.0.1: bytes=32 time<1ms TTL=128 Reply from 127.0.0.1: bytes=32 time<1ms TTL=128 Ping statistics for 127.0.0.1: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 0ms, Average = 0ms