Reputation:
I'm using Powershell(V4) and I'm following the code give here,however, it gives me an error when I run the code.
My Code:
[string]$zipPath="C:\Users\someUser\7z.exe"
[string]$parameters= 'a', '-tzip','C:\Users\someUser\Desktop\Archive.zip','C:\Users\someUser\Desktop\Test'
Powershell View:
PS C:\Users\someUser> $zipPath="C:\Users\someUser\7z.exe" $parameters= 'a', '-tzip','C:\Users\someUser\Desktop\Archive.zip','C:\Users\someUser\Desktop\Test' & $zipPath $parameters
& $zipPath $parameters
Output:
7-Zip (A) 9.20 Copyright (c) 1999-2010 Igor Pavlov 2010-11-18
Error:
Incorrect command line
Upvotes: 2
Views: 4683
Reputation: 202032
That passes all of your arguments as a single string e.g.:
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"
Just pass your arguments normally:
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 is a tool from the PowerShell Community Extensions.
Upvotes: 0
Reputation: 22861
Try using Start-Process
with $parameters
as the -ArgumentList
:
Start-Process $zipPath -ArgumentList $parameters -wait
Upvotes: 1