Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
- Join Date
- Jan 2010
home gui for p7zip with zenity question
zenity --info --text "Choose source file to 7zip using deflate64 /dir in box or click file";
szSavePathfrom=$(zenity --file-selection --multiple --save --confirm-overwrite);
zenity --info --text "Choose file destination";
szSavePathto=$(zenity --file-selection --multiple --save --confirm-overwrite);
7z a -mm=deflate64 $szSavePathto.zip $szSavePathfrom | zenity --progress --text="zipping" --percentage=1 --auto-kill
- Join Date
- Nov 2008
- Tokyo, Japan
Unfortunately, this is easier said than done. 7z is not the most programmer-friendly application.
The "z7" program has a fancy "percent completed" indicator when you run it in the command line, but when you pipe it to a program like zenity, the percent bar is automatically disabled. This is a peculiarity of the "7z" program. Under the hood, what it does is it checks if the "stdout" is a "TTY" file (like "/dev/pts/1") using a command similar in functionality to the "tty" command. If "stdout" is a TTY, then it assumes you executed the "7z" command in the command line and enables the percent indicator.
In bash, when you use the pipe "|" operator, bash creates a new internal file handle for "zenity" and links the output from "7z" to that file handle before executing either program. So when "7z" checks its "stdout" and sees it is not a TTY file (just an ordinary file handle created by bash), it disables the percent indicator.
After scanning through the 7z documentation, and trying Google, I can say with some confidence that there doesn't seem to be any command line option to force the output of a percent indicator, so you are going to have to find a round-about method to accomplish what you want:
- Request a "force percent indicator" feature from the 7z team, or ask around if that feature already exists.
- Download the code for 7z and modify it to force output of percentages.
- Write your own C program to fork "zenity --progress" and "7z -si", then copy byte-by-byte an input file to the "stdin" file handle for "7z -si" while also using printf to write a percentage indicator to the "stdin" file handle of "zenity".
There are ways of counting bytes with the "dd" command, but getting progress information requires saving the process ID for the "dd" command to a variable like "$DD_PID", then periodically sending the "dd" process a signal using "kill -USR1 $DD_PID". Signaling the "dd" program periodically, like once every half-second, will force it to output the number of bytes copied to its "stderr". You would have to redirect the "dd" process's "stderr" to sed to parse that information, then pipe the "sed" output to "zenity".
You can also check out the dcfldd program. If you install it there are options for counting output or duplicating output to multiple files, and figure out a way to tell bash redirect output from "dcfldd" to "7z" while also redirecting the byte counts to "zenity".
I think writing your own C program would be easiest way.