Page 1 of 1

Execute Command for 7-Zip

Posted: Tue Nov 03, 2020 1:56 pm
by magnussandstrom
Hi, I'm trying to use Execute command in Switch to compress and encrypt files using 7-Zip command line program.

When I run the following command 7z a -tzip in.pdf in Windows Command Promt I get a successful ZIP-file. But in Switch I keep getting error code 1 (

The Command or Path is set to: C:/Program Files/7-Zip/7z.exe and the Argument is: a -tzip %1 %2

Any ideas what I'm doing wrong?

ps I'm going to use the XML Pickup for setting the password (but I left this out of the scope for now).
switch_1.jpg (241.22 KiB) Viewed 1167 times
switch_2.jpg (79.66 KiB) Viewed 1167 times

Re: Execute Command for 7-Zip

Posted: Tue Nov 03, 2020 9:39 pm
by Zoranj
First swap %1 and %2 as 7zip needs output path first, than input so it is %2 %1
Also if you have any spaces in your path input or output, it is safer to put quotation marks around it so final commands look like:
a -tzip "%2" "%1"

I hope this helps.

Re: Execute Command for 7-Zip

Posted: Tue Nov 17, 2020 12:03 pm
by magnussandstrom
I got help from Jan to solve this. The main issue was that 7zip creates the compressed file before populating it with compressed data. I use a set folder path instead of %2 and it solved the issue. The varible in my flow looks like this: a -tzip -scrcSHA256 "\\myfolderpath\[Job.NameProper].zip" "%1" -r -p[Job.PrivateData:Key="password"]

a = Add files to archive
-t = Output file type
-scrc = Encryption
-r = Recurse subdirectories
-p = Password

Background: I build this flow to encrypt and send sensitive files to clients etc. I let Switch generate the password and sending the password by SMS from Switch and the file URL by email. It's a really neat flow!

This is the Execute Command settings:
7zip.jpg (83.79 KiB) Viewed 974 times

Re: Execute Command for 7-Zip

Posted: Thu Nov 19, 2020 12:04 pm
by magnussandstrom
And this is the finished flow:
flow.png (116.91 KiB) Viewed 934 times