Powershell - 使用带参数的 7zip

Powershell - Using 7zip with Parameters

我正在使用 Powershell(V4),我正在按照代码给出 here,但是,当我 运行 代码时它给了我一个错误。

我的代码:

[string]$zipPath="C:\Users\someUserz.exe"
[string]$parameters= 'a', '-tzip','C:\Users\someUser\Desktop\Archive.zip','C:\Users\someUser\Desktop\Test'

Powershell 视图:

PS C:\Users\someUser> $zipPath="C:\Users\someUserz.exe" $参数= 'a', '-tzip','C:\Users\someUser\Desktop\Archive.zip','C:\Users\someUser\Desktop\Test' & $zipPath $参数

& $zipPath $parameters

输出:

7-Zip (A) 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18


 Error:
 Incorrect command line

尝试使用 Start-Process$parameters 作为 -ArgumentList:

Start-Process $zipPath -ArgumentList $parameters -wait

将所有参数作为单个字符串传递,例如:

2> $ec = 'echoargs'
3> & $ec $parameters
Arg 0 is <a -tzip C:\Users\someUser\Desktop\Archive.zip C:\Users\someUser\Desktop\Test>

Command line:
"C:\Users\hillr\Documents\WindowsPowerShell\Modules\Pscx\Apps\EchoArgs.exe"  "a -tzip C:\Users\someUser\Desktop\Archive.
zip C:\Users\someUser\Desktop\Test"

正常传递参数即可:

4> & $ec a -tzip C:\Users\someUser\Desktop\Archive.zip C:\Users\someUser\Desktop\Test
Arg 0 is <a>
Arg 1 is <-tzip>
Arg 2 is <C:\Users\someUser\Desktop\Archive.zip>
Arg 3 is <C:\Users\someUser\Desktop\Test>

Command line:
"C:\Users\hillr\Documents\WindowsPowerShell\Modules\Pscx\Apps\EchoArgs.exe"  a -tzip C:\Users\someUser\Desktop\Archive.z
ip C:\Users\someUser\Desktop\Test

BTW echoargs 是 PowerShell Community Extensions.

中的一个工具