Trigger 7-ZIP via Start Process - Automatically closes before extraction is complete

Hi. I am extracting a daily ZIP file into a existing folder and starting the process via a Start Process activity which starts 7-ZIP and provides the required arguments. The reason I am using 7-ZIP is that after the extraction is done I need to identify new files received within the last day. When I use the inbuilt unzip activity is changes the file creation/modification date to the date/time the extraction is done, whereas 7-ZIP maintains the date/time of the original file in the ZIP file.

I have the correct arguments in the Start Process activity, however the problem I have is that the command prompt is closed after it starts before the extraction has had a chance to run. I have changed the Execution Type from both Asynchronously and Synchronously but this didn’t make any difference. Also set the Timeout but this didn’t change anything.

Any suggestions how I can keep the command window open until it completes the extraction, or another way to trigger 7-ZIP?

Thanks
Craig…

Hi,

How about using System.Diagnostics.Process and System.Diagnostics.ProcessStartInfo?

The following is a simple sample for them.

image

Dim pinfo As System.Diagnostics.ProcessStartInfo = New System.Diagnostics.ProcessStartInfo()
pinfo.FileName = System.IO.Path.Combine(System.Environment.GetEnvironmentVariable("USERPROFILE"),"AppData\Local\Programs\UiPath\Studio","UiPath.LicenseTool.exe")
pinfo.RedirectStandardError = True
pinfo.RedirectStandardOutput = True
pinfo.UseShellExecute =False
pinfo.Arguments ="info"
Dim p As System.Diagnostics.Process = New System.Diagnostics.Process()
p.StartInfo = pinfo
p.Start()
p.WaitForExit()
out_content  = p.StandardOutput.ReadToEnd()
out_stderr = p.StandardError.ReadToEnd()

Sample20230815-2L.zip (2.6 KB)

Regards,

Hi @Yoichi . I have tried both Invoke Code and Start Process activity. The outcome is the same being that the CMD window opens to execute the command but close straight away even though the process inside the CMD window hasn’t completed.

Hi,

How about the following code? (Set UseShellExecute True)

Dim pinfo As System.Diagnostics.ProcessStartInfo = New System.Diagnostics.ProcessStartInfo()
pinfo.FileName = "C:\Program Files\7-Zip\7z.exe"
pinfo.UseShellExecute =True
pinfo.Arguments ="x targetfile.zip"
Dim p As System.Diagnostics.Process = New System.Diagnostics.Process()
p.StartInfo = pinfo
p.Start()
p.WaitForExit()

BTW, what is your purpose to keep cmd window open?
The first my sample returns output of console as string variable.

Regards,

Hi @Yoichi . I needed to add some additional double quotes around the file name and path to handle spaces in the file path.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.