Commandline Zip - progressbar - logfile - 7z or 7zG Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Albireo
Posts: 1747
Joined: 16 Oct 2013, 13:53

Commandline Zip - progressbar - logfile - 7z or 7zG

07 May 2020, 12:45

Hi!
I want to compress some files with AHK and found 7-zip (it works pretty well)

1) Progress bar
Normally I run 7z.exe from command line with this parameters (and it works in some way)

Code: Select all

	RunArgs := "a -w" WorkPath " -t7z -stl -p" PassWd " -mhe=on -sccUTF-8 -bb1 -bse2 -bsp1 > " ResInfoFile
	RunWait %comspec% /c ""%exeFile%" %RunArgs% "%ToZip%" "%SourceFile%"",, hide UseErrorLevel, ZipPID
But when the compression phase takes some time (I don't see anything on the screen)
Would I like to see that something happens (some progress bar)

I can instead use 7zG.exe and this program gives me running information as progress bar and status information about files and compression size and so on. (nice!)

Summary - Progressbar
My wish is to get a progress bar (similar to 7zG.exe) when zipping many / large files. (An analysis can be done in AHK if the progress bar should be displayed or not), but at the same time create a log file.
Is it possible with AHK?



2) Logfile / Run information
( I don't understand how 7zip logfiles work )
As result I got some information from 7-zip (like that)
An excerpt from the log from 7z.exe
(it contains about 26,000 rows - the last rows was added by my AHK-program)

7z.exe gives some kind of result (as above)
7zG.exe does not create a log file at all (with the same settings as for 7z.exe)

If I understand correctly, 7z.exe can generate three files with results
  • bso - standard output messages
  • bse - error messages
  • bsp - progress information

I don't know the meaning of
  • redirect to stdout stream
  • redirect to stderr stream
and the -bb (Set output log level) switch

Summary - log file
Right now I don't know if it is an AHK problem or something I dont understand with 7zip.

My wish is primarily to get an error message if something unexpected happens (what happened - missing files, locked files or ...)
Also want to get some information.: How many files have been compressed, how long did it take, etc. - and maybe I want to know which files have been compressed and how much they have been compressed. But preferably in any format that has been easier to handle with e.g. LO Calc or Excel or ...
User avatar
Smile_
Posts: 857
Joined: 03 May 2020, 00:51

Re: Commandline Zip - progressbar - logfile - 7z or 7zG

07 May 2020, 13:59

You don't see anything on your screen because you are hiding the Command Prompt window with Hide option in

Code: Select all

RunWait %comspec% /c ""%exeFile%" %RunArgs% "%ToZip%" "%SourceFile%"",, hide UseErrorLevel, ZipPID
                                                                         ^
Just remove it and you will be able to see your compression progress (only hide don't remove anything else).
Also in the log file you got there is line says Created from file .: C:\...\7-zip - Pack v2.ahk.
Seems it is not 7z.exe that created the Log file, is it the Ahk Script?, I think yes.
You will get enough informations about compressing process but Progress Bar, I D K if that possible, because the 7z.exe is designed to show informations in the CMD window not in GUI as I noticed.
This waht you can do with 7-Zip 19.00 at least with the version I have now:
7zip Command Lines:
Albireo
Posts: 1747
Joined: 16 Oct 2013, 13:53

Re: Commandline Zip - progressbar - logfile - 7z or 7zG

07 May 2020, 16:03

When I removed hide from the instruction, only a black CMD window opens. (nothing in it)
Maybe it can be something with -bb1 -bse2 -bsp1 (I dont understand how to handle this switches)
User avatar
Smile_
Posts: 857
Joined: 03 May 2020, 00:51

Re: Commandline Zip - progressbar - logfile - 7z or 7zG

07 May 2020, 17:36

Ok let us make it clearier.
Basically you are running CMD command via Autohotkey, which means you can execute it directly via CMD window (No need for Autohotkey).
I told you to remove hide because you said you cannot see anything on screen, so I didn't paid much attention to your command.
Lets talk about your command now, in CMD using ">" means to send what you see on the window to a file (like FileAppend in authotkey) and that lead to a black window of CMD as result.
In the next examples Ill use = instead of :=, because := wont help us here.
Lets try again with simpler command, this will display you compress progress infos in CMD window:

Code: Select all

RunArgs = a -p"Password"
RunWait %comspec% /c ""7z.exe" %RunArgs% "ArchiveName" "FileorFolderToCompress""
and this wont show you anything:

Code: Select all

RunArgs = a -p"Password"
RunWait %comspec% /c ""7z.exe" %RunArgs% "ArchiveName" "FileorFolderToCompress" > Log.txt"
because you send the CMD output to Log.txt, to know waht happened open Log.txt everything will be there.
Variables are like this:
Password: Password that you want to add.
ArchiveName: The archive file name for example (Archive.7z), you can also specify path to where you want it, example (C:\Archive.7z).
FileorFolderToCompress: Use fullpath to avoid getting errors.

Lets try with your example:

Code: Select all

RunArgs := "a -w" WorkPath " -t7z -stl -p" PassWd " -mhe=on -sccUTF-8 -bb1 -bse2 -bsp1 > " ResInfoFile
Not a correct command, the second quote stops at no meaning position this way the program attemting to execute this
"7z.exe" a -w -t7z -stl -p -mhe=on -sccUTF-8 -bb1 -bse2 -bsp1 > "%ToZip%" "%SourceFile%", which will just cause of unexpected exit because ">" exist in wrong place so CMD won't understand that so it exits and then nothing will happen (also password and working directory are not exist because of using :=, when the chosen argument assigned to RunArgs).
Lets try with this now:

Code: Select all

RunArgs = a -w" WorkPath " -t7z -stl -p" PassWd " -mhe=on -sccUTF-8 -bb1 -bse2 -bsp1
RunWait %comspec% /c ""7z.exe" %RunArgs% "%ToZip%" "%SourceFile%"",,UseErrorLevel, ZipPID
Yes that can work. Note: you have to specify the WorkPath else if WorkPath directory doesn't exist wont compress, as well %ToZip% and %SourceFile%
%ToZip%: ArchiveName.
%SourceFile%: FileorFolderToCompress.
This works if 7z.exe exist in same directory with the Ahk script else you have to specify where is 7z.exe example (C:\Program Files\7-Zip\7z.exe ) or it wont work.
Last thing limit your files or folders names with 2 quotes if they contain spaces because the 7z.exe knows the next argument after space (can be one space or more) it find, so if it find space in your Archive Name for example it will consider the thing after space as argument which can be a cause of a problem.
About the switchs you
If you ask me about that, Ill say, it is not needed to do all of this, just open your CMD and do your work, same as 7zG.exe.
If you needed any help with CMD commands let me know.
This can help you to understand the switchs: https://sevenzip.osdn.jp/chm/cmdline/
I attached you 7za.exe ( (a = alone) is a standalone version of 7-Zip, No 7-Zip installation needed).

I tried to explain as easier as I can. Hope it helps.
Attachments
7za.zip
7-Zip (a) [32] 16.02
(342.73 KiB) Downloaded 107 times
Albireo
Posts: 1747
Joined: 16 Oct 2013, 13:53

Re: Commandline Zip - progressbar - logfile - 7z or 7zG

08 May 2020, 05:21

Thank you for your dedication!
(like your attempt at explanation - even if it didn't lead to a solution for me)

I've done some tests - based on your explanations.

Creating a RunArgs variable, which works with 7-zip, has not been easy.
(but I got some help - Run a command line program and capture the result - the question started with the program IZArc Command Line Add-On v1.1)

Is it better to run 7-zip, not through CMD? (but it is more difficult to redirect the output)

Code: Select all

RunWait %exeFile% %RunArgs% "c:\Temp\7zip.7z" "%SourceFile%"

I think RunArgs := "a -w" WorkPath " -t7z -stl -p" PassWd " -mhe=on -sccUTF-8 -bb1 -bse2 -bsp1" works as variable with 7-zip (with no problem). You are absolutely right about the redirect sign <, that it changes the flow of information from 7-zip

What I am trying to do is to be able to see the compression process and at the same time get a basis for any errors and problems (Have all files been packed or ...)
If this information is only on the screen, the information is gone after the program is terminated.

If it takes more than a few seconds to package the files, my wish is to be able to follow what happens (here I think 7zG.exe is good), but how to create some log files from the run at the same time? (is it possible?)

___________________________________________
___________________________________________
I tried to create some errors with the following RunArgs
(Your RunArgs)

Code: Select all

RunArgs = a -w" WorkPath " -t7z -stl -p" PassWd " -mhe=on -sccUTF-8 -bb1 -bse2 -bsp1
RunWait %comspec% /c ""%exeFile%" %RunArgs% "%ToZip%" "%SourceFile%"",,UseErrorLevel, ZipPID
From 7z.exe, 7za.exe
CMD windows appear in milliseconds (and closes)
(No error is displayed)

From my AHK
Fatal error! (Exit Code .: 2)
____

From 7zG.exe (freely translated from swedish)
Wrong function.
and
Unable to open the encrypted archive. Wrong password?

From my AHK
Fatal error! (Exit Code .: 2)

___________________________________________
___________________________________________
(RunArgs1 doesn't exist)

Code: Select all

RunWait %comspec% /c ""%exeFile%" %RunArgs1% "%ToZip%" "%SourceFile%"",,UseErrorLevel, ZipPID
From 7za.exe, 7z.exe
(No response)

From my AHK
Command line error! (Exit Code .: 7)
____

From 7zG.exe
Unsupported command: c:\temp\Test.7z

From my AHK
Command line error! (Exit Code .: 7)

___________________________________________
___________________________________________
(But as expected, no logs are created)
User avatar
Smile_
Posts: 857
Joined: 03 May 2020, 00:51

Re: Commandline Zip - progressbar - logfile - 7z or 7zG

08 May 2020, 08:53

@Albireo
RunArgs = a -w" WorkPath " -t7z -stl -p" PassWd " -mhe=on -sccUTF-8 -bb1 -bse2 -bsp1
RunWait %comspec% /c ""%exeFile%" %RunArgs% "%ToZip%" "%SourceFile%"",,UseErrorLevel, ZipPID
did you specified the work path?
Password is not important.
Last edited by Smile_ on 08 May 2020, 09:44, edited 2 times in total.
User avatar
Smile_
Posts: 857
Joined: 03 May 2020, 00:51

Re: Commandline Zip - progressbar - logfile - 7z or 7zG

08 May 2020, 09:29

@Albireo
From 7z.exe, 7za.exe
CMD windows appear in milliseconds (and closes)
(No error is displayed)
Try with this :

Code: Select all

RunArgs = a -w"%WorkPath%" -t7z -stl -p"PassWd" -mhe=on -sccUTF-8 -bb1 -bse2 -bsp1
FileDelete, Compress.bat
FileAppend, @Echo off`nColor 0e`n%exefile% %RunArgs% "%ToZip%" "%SourceFile%"`nEcho.`nEcho Press anykey to exit.`nPause>nul, Compress.bat
RunWait, Compress.bat
This must pause the script after you execute your argument so you will be able to see what happened (You will see output in yellow) .
User avatar
Smile_
Posts: 857
Joined: 03 May 2020, 00:51

Re: Commandline Zip - progressbar - logfile - 7z or 7zG

08 May 2020, 10:20

@Albireo
I created some examples for you to see how this works:

Example 1:
This will execute a command and then close the CMD window directly.

Code: Select all

FileDelete, Example.bat
FileAppend, @Echo off`nEcho Hello World., Example.bat
RunWait, Example.bat
Return
Example 2:
This will execute a command and then hold the CMD window for a while (about 5 seconds).

Code: Select all

FileDelete, Example.bat
FileAppend, @Echo off`nEcho Hello World.`nping localhost -n 6 >nul, Example.bat
RunWait, Example.bat
Return
Example 3:
This will execute a command and then hold the CMD window forever unless you click a key to exit .

Code: Select all

FileDelete, Example.bat
FileAppend, @Echo off`nEcho Hello World.`npause>nul, Example.bat
RunWait, Example.bat
Return
Waht Compress.bat contain?
Example 3: It contain this.
@Echo off
Echo Hello World.
pause>nul
You can create a Compress.bat file and paste these three lines (Commands) inside it, gives you same result.
This is waht I did with in

Code: Select all

RunArgs = a -w"%WorkPath%" -t7z -stl -p"PassWd" -mhe=on -sccUTF-8 -bb1 -bse2 -bsp1
FileDelete, Compress.bat
FileAppend, @Echo off`nColor 0e`n%exefile% %RunArgs% "%ToZip%" "%SourceFile%"`nEcho.`nEcho Press anykey to exit.`nPause>nul, Compress.bat
RunWait, Compress.bat
It doesn't run the command from AHK script, it just move that command to a bat file and then run that file, so now AHK script will have to wait until the CMD Window closed by you.
Last edited by Smile_ on 08 May 2020, 18:20, edited 1 time in total.
Albireo
Posts: 1747
Joined: 16 Oct 2013, 13:53

Re: Commandline Zip - progressbar - logfile - 7z or 7zG

08 May 2020, 11:56

(On the first question - Yes!
When I inserted your code (and a MsgBox), the following results were created!

Code: Select all

	RunArgs = a -w"%WorkPath%" -t7z -stl -p"PassWd" -mhe=on -sccUTF-8 -bb1 -bse2 -bsp1
	MsgBox % "exeFile . . . . .: " exeFile "`nWorkPath . . .: " WorkPath "`nPassWd  . . . .: " PassWd "`nToZip  . . . . . .: " ToZip "`nSourceFile .: " SourceFile "`nRunArgs .: " RunArgs
	
	FileDelete, Compress.bat
	FileAppend, @Echo off`nColor 0e`n%exefile% %RunArgs% "%ToZip%" "%SourceFile%"`nEcho.`nEcho Press anykey to exit.`nPause>nul, Compress.bat
	RunWait, Compress.bat
From the MsgBox above .:
exeFile . . . . .: C:\Program Files\7-Zip\7zG.exe
WorkPath . . . .: c:\ProgExpo\Temp
PassWd . . . . .: Secret
ToZip . . . . . .: c:\temp\Test.7z
SourceFile . . .: c:\temp\OutletFTP\
RunArgs .: a -w"c:\ProgExpo\Temp" -t7z -stl -p"PassWd" -mhe=on -sccUTF-8 -bb1 -bse2 -bsp1
and from the CMD (but the text is yellow - not black)
'C:\Program' is not recognized as an internal or external command, operable program or batch file.

Press anykey to exit.


A look back
I want to see what happens when a program is running (7z.exe), while creating a file with the same content.
I found a good explanation for the problem on this page Batch How To Display & Redirect Output

If 7-zip not can handle this, I must find another solution. (I still wondering if the 7-zip switch -bb1 "show names of processed files in log" can do this). The tee utility is typically present in PowerShell and Unix/Linux systems. I've been looking for some similar solution for Windows.

I found robvanderwounde with many bat-examples
The Code .: TEE.bat
TEE - C-code
I have also found TEE.exe in GnuWin32

Also found an old topic on AHK .: Display AND copy output of command line operation
(cb.exe - not found and missing information) and pipesplit.exe (by @Chris)
pipesplit.exe works in the CMD window.

If I run this command in a CMD window .: (PipeSplit is in C:\Program Files\7-Zip)

Code: Select all

C:\Program Files\7-Zip>7zG a -wc:\ProgExpo\Temp -t7z -stl -pSecret -mhe=on -sccUTF-8 -bb3 -bse1 c:\temp\7zip.7z c:\temp\OutletFTP | PipeSplit c:\temp\7zip.txt
I can look on the GUI from 7-zip, and a logfile is created.
(Swedish characters also appear to be managed with the switch -sccUTF-8)
  • My next steps are .:
    1) Create this CMD-command (above) in AHK (with variables and everything)
    2) See if it is possible to handle both Output and Error in different ways (as these seem to be handled different)
User avatar
Smile_
Posts: 857
Joined: 03 May 2020, 00:51

Re: Commandline Zip - progressbar - logfile - 7z or 7zG

08 May 2020, 12:17

@Albireo
Can I see the code you used in AHK script to compress with 7z.exe or 7za.exe?, full script please.
User avatar
Smile_
Posts: 857
Joined: 03 May 2020, 00:51

Re: Commandline Zip - progressbar - logfile - 7z or 7zG

08 May 2020, 12:42

@@Albireo
RunArgs = a -w"%WorkPath%" -t7z -stl -p"PassWd" -mhe=on -sccUTF-8 -bb1 -bse2 -bsp1
MsgBox % "exeFile . . . . .: " exeFile "`nWorkPath . . .: " WorkPath "`nPassWd . . . .: " PassWd "`nToZip . . . . . .: " ToZip "`nSourceFile .: " SourceFile "`nRunArgs .: " RunArgs

FileDelete, Compress.bat
FileAppend, @Echo off`nColor 0e`n%exefile% %RunArgs% "%ToZip%" "%SourceFile%"`nEcho.`nEcho Press anykey to exit.`nPause>nul, Compress.bat
RunWait, Compress.bat
put %exefile% between 2 quotes so It would be like this

Code: Select all

FileAppend, @Echo off`nColor 0e`n"%exefile%" %RunArgs% "%ToZip%" "%SourceFile%"`nEcho.`nEcho Press anykey to exit.`nPause>nul, Compress.bat
Sorry forgot to add that, because I'm not using C:\Program Files\7-Zip\7zG.exe I just use exe name.
C:\Program Files\7-Zip\7zG.exe contain spaces, so it must be quoted.

You got that because CMD when attempt to execute C:\Program Files\7-Zip\7zG.exe stops at first space and assumed that C:\Program is the executable to execute which doesn't exist so it says 'C:\Program'' is not recognized as an internal or external command, operable program or batch file.
Albireo
Posts: 1747
Joined: 16 Oct 2013, 13:53

Re: Commandline Zip - progressbar - logfile - 7z or 7zG

08 May 2020, 12:46

Thanks for your example (an observation - example 1-3)
  1. - FileDelete, Example.bat
  2. - FileAppend, ... Compress.bat
  3. - RunWait, Example.bat
(maybe it should be the same filename in all instructions? ;) )

I think you also understand the possibility of different output steam for output/error/progress line in 7-zip
Now it's just being able to handle this (as I see it)

From 7-zip help file 7z t a.7z -bse1> messages.txt
That is clear a.7z is tested and error messages is redirected to the stdout steam and also saved in the file messages.txt (the same as - if i understand this correctly) 7z t a.7z -bso1 -bse1> messages.txt

How to catch the error steam and sent it to a file and the steam for the output to the window
(with tee or PipeSplit I can send the steam to window - and file.)

The least I want is, for any errors and problems to be saved in a log file.
On the screen I want to see the progress.
User avatar
Smile_
Posts: 857
Joined: 03 May 2020, 00:51

Re: Commandline Zip - progressbar - logfile - 7z or 7zG

08 May 2020, 13:06

Thanks for your example (an observation - example 1-3)
- FileDelete, Example.bat
- FileAppend, ... Compress.bat
- RunWait, Example.bat
Yes Compress.bat is supposed to be Example.bat, just forget to change that, if you see first example all are similar.

From the link you pasted()
Examples
7z t a.7z -bse1 > messages.txt
tests a.7z archive and sends error messages to stdout that is redirected to messages.txt
We understand from it that error / progress line (no progress line only percentage progress with 7z.exe or 7za.exe) are all sent to messages.txt.
error / progress will be shown in window, and output when it is setted is to get waht is shown in that Window.
On the screen I want to see the progress.
On screen you can see both Errors and Progress, don't use '> messages.txt' If so.
Albireo
Posts: 1747
Joined: 16 Oct 2013, 13:53

Re: Commandline Zip - progressbar - logfile - 7z or 7zG

08 May 2020, 13:52

Thanks for your time!

Don't know if my program can provide something (it's almost 500 lines and a lot of text in Swedish).
And I wasn't going to (at this moment) lift this part out.

Right now I can't see any big difference between these three ways of compressing files (if everything works as desired).

1)

Code: Select all

RunArgs := "a -w" WorkPath " -t7z -stl -p" PassWd " -mhe=on -sccUTF-8 -bb3 -bse1"
RunWait %comspec% /c ""%exeFile%" %RunArgs% "%ToZip%" "%SourceFile%"",, UseErrorLevel, ZipPID
2)

Code: Select all

RunArgs := "a -w" WorkPath " -t7z -stl -p" PassWd " -mhe=on -sccUTF-8 -bb3 -bse1"
RunWait %exeFile% %RunArgs% "%ToZip%" "%SourceFile%",, UseErrorLevel, ZipPID
3)

Code: Select all

RunArgs = a -w"%WorkPath%" -t7z -stl -p"PassWd" -mhe=on -sccUTF-8 -bb1 -bse2 -bsp1
FileDelete, Compress.bat
FileAppend, @Echo off`nColor 0e`n"%exefile%" %RunArgs% "%ToZip%" "%SourceFile%"`nEcho.`nEcho Press anykey to exit.`nPause>nul, Compress.bat
RunWait, Compress.bat
Comments
All these three examples give the same results. (only the 7z-file - no error file)
1 and 3 is easy to redirect the output
I know how to handle errors from 1 and 2 (not tested how to handle errors from 3)
(It can be difficult to provoke different error messages)
For me, it is important to handle the errors correctly (have not decided how)
but when a user comes to the computer and a serious error has occurred, they may contact me.
Otherwise it might be enough with an email or SMS or …

Probably I will do an analysis of the files to be compressed before compression. Will it run fast I will run 7z.exe / 7za.exe If it is a backup it may take considerably longer and then I wish to run 7zG.exe (my ZipFunction() can decide which program to use) my ZipFunction() can also read the files created by 7-zip - if an Error file was created it should be handled

But now I want to create my logfiles with 7-zip or redirect on some way or as i wrote
Albireo wrote:
08 May 2020, 11:56
  • My next steps are .:
    1) Create this CMD-command in AHK (with variables and everything)

    Code: Select all

    C:\Program Files\7-Zip>7zG a -wc:\ProgExpo\Temp -t7z -stl -pSecret -mhe=on -sccUTF-8 -bb3 -bse1 c:\temp\7zip.7z c:\temp\OutletFTP | PipeSplit c:\temp\7zip.txt
    2) See if it is possible to handle both Output and Error in different ways (as these seem to be handled different)
User avatar
Smile_
Posts: 857
Joined: 03 May 2020, 00:51

Re: Commandline Zip - progressbar - logfile - 7z or 7zG

08 May 2020, 18:09

I feel like there is something missing, if you can contact me with another way maybe it can clearify things more, like Discord for example.
Facebook Messenger good too.

@Albireo

[Assuming that the Errors are syntax Errors and and the Output is the shown informations inside CMD window hidden or not.]
1) Create this CMD-command in AHK (with variables and everything)

Code: Select all

ExeFile = C:\Program Files\7-Zip\7zG.exe
RunArgs = a -w"c:\ProgExpo\Temp" -t7z -stl -p"Secret" -mhe=on -sccUTF-8 -bb3 -bse1
ToZip = c:\temp\7zip.7z
SourceFile = c:\temp\OutletFTP
PipeLog = "C:\Program Files\7-Zip\PipeSplit.exe" "c:\temp\7zip.txt"

RunWait %comspec% /c " "%ExeFile%" %RunArgs% "%ToZip%" "%SourceFile%" | "%PipeLog%" ",, UseErrorLevel, ZipPID
RunWait, c:\temp\7zip.txt
(I don't think that PipeSplit.exe will create an output log to c:\temp\7zip.txt since CMD window is blank.)
2) See if it is possible to handle both Output and Error in different ways (as these seem to be handled different)
As I see:

With 7zG.exe Output/Error is already handled with the GUI, you can see Output informations, and Errors if occured.
So Output/Error Log cannot be created since the CMD window is blank all the time.

With 7z.exe yes, you can create log file for Output.
Like this:

Code: Select all

ExeFile = C:\Program Files\7-Zip\7z.exe
RunArgs = a -w"c:\ProgExpo\Temp" -t7z -stl -p"Secret" -mhe=on -sccUTF-8 -bb3 -bse1
ToZip = c:\temp\7zip.7z
SourceFile = c:\temp\OutletFTP
Output = c:\temp\7zip.txt

RunWait %comspec% /c " "%ExeFile%" %RunArgs% "%ToZip%" "%SourceFile%" >> "%Output%"  ",, UseErrorLevel, ZipPID
RunWait, c:\temp\7zip.txt
If there was an ERROR also should be exported to c:\temp\7zip.txt.

Actually I searched on the Tee utility that you wrote about:

Code: Select all

ExeFile = C:\Program Files\7-Zip\7z.exe
RunArgs = a -w"c:\ProgExpo\Temp" -t7z -stl -p"Secret" -mhe=on -sccUTF-8 -bb3 -bse1
ToZip = c:\temp\7zip.7z
SourceFile = c:\temp\OutletFTP
Output = c:\temp\7zip.txt
Mtee = C:\Program Files\7-Zip\Mtee.exe

RunWait %comspec% /c " "%ExeFile%" %RunArgs% "%ToZip%" "%SourceFile%" | "%Mtee%" /+ "%Output%" ",, UseErrorLevel, ZipPID
RunWait, %Output%
This gonna display you the current active Output in CMD window and then store final Output log to c:\temp\7zip.txt that contain last shown Output in CMD.
Attachments
mtee.zip
The Tee Utility
(7.98 KiB) Downloaded 74 times
Albireo
Posts: 1747
Joined: 16 Oct 2013, 13:53

Re: Commandline Zip - progressbar - logfile - 7z or 7zG

10 May 2020, 10:45

Thank you @Smile_ for the offer to help me in other ways, (but I think my current solution will suit me - right now).
1) I have tested a lot with 7z.exe 7za.exe 7zG.exe

1a) I cannot use 7zG.exe - Can only create the compressed file, all information is produced on GUI (progress / output / error).
A log file (or errorfile) can never be produced by 7zG.exe. Just as you say, CMD will always be blank together with 7zG.exe (I read that this may be solved in the next version - we'll see)

1b) 7za.exe - Works fine (I have no problem) but it can be slower tha 7z.exe (have not tested) From 7z vs 7za
  • 7za.exe version 9.20 took 11 min 33 seconds (with the -mx1 setting)
  • 7za.exe version 19.0 took 54 seconds (with the -mx1 setting)
(your 7za.exe is version 16.02 - 2016-05-21 and my 7z.exe is version 19.00 - 2019-02-21)
Have only tested the compatibility (and it seems to be good), but the development will always be at 7z.exe

2) I made a variation on your solution, that shows both a result in the CMD window and creates a file with the same content, as well as creates a file with error messages. (it works!)

Code: Select all

RunArgs := "a -w" WorkPath " -t7z -stl -mx=" CompLevel " -p" PassWd " -mhe=on -scsUTF-8 -sccUTF-8 -bb3 -bsp1 -bso1 -bse2 "
RunWait %comspec% /c ""%exeFile%" %RunArgs% "%ToZip%" "%SourceFile%" 2> "%ErrFile%" | "%TeeProg%" "%InfoFile%"",, UseErrorLevel, ZipPID
(that was before I saw your attachment mtee.exe)
The limitations I experience with this solution are -
  • - No nice graphic presentation of the course of events.
  • - An "error file" is always created with or without error messages.
  • - UTF-8 in the RunArgs causes the files can be created with Swedish characters as ÅÄÖ (but in the CMD window it looks strange)
  • - In the output file I add my own information such as packing rate, compression time, RunArgs etc. - that information always comes last in the file. It would have been better if that information had come first in the file. (The easiest way is probably to load the entire file and then rewrite it?)
3)MTEE.exe (haven't tested yet) but it seems to be a program I have been looking for.
I want to look / test what MTEE.exe does (it also has FTP features that I want to test)
Have understood that different programs with tee function can be different fast (but in my case I do not think it does matter)

Has been a bit tricky to compare different programs - the first time the program runs takes a long time - the second time goes much faster ... (do not know how to turn off / clear the cache between tests)
User avatar
Smile_
Posts: 857
Joined: 03 May 2020, 00:51

Re: Commandline Zip - progressbar - logfile - 7z or 7zG  Topic is solved

10 May 2020, 12:35

- No nice graphic presentation of the course of events.
7z.exe and 7za.exe are console applications, you can't make it build you graphic interface, it can only display you progress information on the console window or in a file as you did, unless you use an external program that check source file size and the compressed size and make calculation about passed time and remaining time, and calculate the progress with percentage view and add an progress bar that much with that percentage and place them inside GUI and show it, the GUI must be instantly updated with the new informations of the compress progress, with Autohotkey that can be done? yes, but it wont be easy to do as you see I described it.(You have that already done with 7zG.exe).
- An "error file" is always created with or without error messages.
If that bothering you, after compression done check the Error file content then delete if it is empty.(You wont see that file after compression done if there is no errors).
- UTF-8 in the RunArgs causes the files can be created with Swedish characters as ÅÄÖ (but in the CMD window it looks strange)
Not any character can be displayed in CMD window.
Check this :
:arrow: https://superuser.com/questions/1362080/which-characters-are-invalid-for-an-ms-dos-filename

Code: Select all

- In the output file I add my own information such as packing rate, compression time, RunArgs etc. - that information always comes last in the file. It would have been better if that information had come first in the file. (The easiest way is probably to load the entire file and then rewrite it?)
No need to load the entire file and then rewrite it.
It can be done this way with Mtee.exe (I D K about other tee programs) :

Code: Select all

FileAppend, `n-----------------`nMy Own Informations Here`n-----------------`n , %Output%    ; Append your informations to %Output% before starting the compress process.
RunWait %comspec% /c ""%exeFile%" %RunArgs% "%ToZip%" "%SourceFile%" 2> "%ErrFile%" | "%TeeProg%" /+ "%Output%"",, UseErrorLevel, ZipPID
; Use /+ after %TeeProg% to append instead of overwriting %Output%, so your informations that you added will be not lost which means it is always top of the compressing output.
I want to look / test what MTEE.exe does (it also has FTP features that I want to test)
I D K for waht you need that but yes it has.
For more informations about Mtee.exe commands
:arrow: https://ritchielawrence.github.io/mtee/
Albireo
Posts: 1747
Joined: 16 Oct 2013, 13:53

Re: Commandline Zip - progressbar - logfile - 7z or 7zG

10 May 2020, 18:26

Don't think I can do more - right now
The latest version of the test program was like this

Code: Select all

#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%
SetBatchLines -1
#SingleInstance Force

StartTime := A_TickCount

PassWd := "Secret"
CompLevel := "1"
; SourceFile := "c:\temp\OutletFTP"
SourceFile := "c:\Squid2"
ToZip := "c:\temp\7zipSquid.7z"
InfoFile := "c:\temp\7zip.txt"
ErrFile := "c:\temp\Error.txt"

ExeFile := "C:\Program Files\7-Zip\7z.exe"
TeeProg := "C:\Program Files\7-Zip\Mtee.exe"
WorkPath := "c:\ProgExpo\Temp"

If FileExist(InfoFile)
	FileDelete %InfoFile%
If FileExist(ToZip)
	FileDelete %ToZip%
If FileExist(ErrFile)
	FileDelete %ErrFile%

RunArgs := " a -w" WorkPath " -t7z -stl -mx=" CompLevel " -p" PassWd " -mhe=on -scsUTF-8 -sccUTF-8 -bb3 -bsp1 -bso1 -bse2 "
RunWait %comspec% /c ""%exeFile%" %RunArgs% "%ToZip%" "%SourceFile%" 2> "%ErrFile%" | "%TeeProg%" /+ "%InfoFile%"",, UseErrorLevel, ZipPID

FileRead Result, *p65001 %InfoFile%
FileDelete %InfoFile%
FileAppend % "RunArgs `n" RunArgs "`n`nRuntime .: " A_TickCount - StartTime "ms`n`n - - - - - - - - - -`n`n" Result, %InfoFile%, UTF-8

if FileExist(ErrFile)
{	FileGetSize ErrFileSize, %ErrFile% 
	if (ErrFileSize < 4)
		FileDelete %ErrFile%
	else
	{	Run Notepad.exe %ErrFile%
	}
}


MsgBox 262144, Rad %A_LineNumber% -> %A_ScriptName%, % A_TickCount - StartTime "ms`n`nReady!"
User avatar
Smile_
Posts: 857
Joined: 03 May 2020, 00:51

Re: Commandline Zip - progressbar - logfile - 7z or 7zG

10 May 2020, 19:00

An Improvement I see in your script @Albireo :
Instead of this

Code: Select all

If FileExist(InfoFile)
	FileDelete %InfoFile%
If FileExist(ToZip)
	FileDelete %ToZip%
If FileExist(ErrFile)
	FileDelete %ErrFile%
You can do this

Code: Select all

For index, File in [ToZip, InfoFile, ErrFile]
	If FileExist( File )
		FileDelete, % File
Congras! @Albireo
By the way choosing 7-zip to compress your files was the best choice, I searched before about compressing methods and I never found something better than 7-zip, I always find 7-zip compress with size lower than others. I really enjoyed this conversation and you actually benefited me with some valuable informations made my vision to CMD commands more clear, Thank you and Good luck.
Albireo
Posts: 1747
Joined: 16 Oct 2013, 13:53

Re: Commandline Zip - progressbar - logfile - 7z or 7zG

11 May 2020, 02:27

Thanks to you too!
Smile_ wrote:
10 May 2020, 19:00
...
Instead of this

Code: Select all

If FileExist(InfoFile)
	FileDelete %InfoFile%
If FileExist(ToZip)
	FileDelete %ToZip%
If FileExist(ErrFile)
	FileDelete %ErrFile%
You can do this

Code: Select all

For index, File in [ToZip, InfoFile, ErrFile]
	If FileExist( File )
		FileDelete, % File
Have to look at it. The only thing is that you should add an error handling - if someone has opened and locked one of the result files and this should be handled differently, it can be a bit tricky to handle with a loop.

Found an "error" in this test code (mtee /+ "c:\temp\InfoFile.txt") must in this case be (mtee "c:\temp\InfoFile.txt")

I wonder about further improvements.
Is it possible - instead of redirecting the result to a file - redirecting the result to a variable - but it may be another question.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: hugojans and 95 guests