Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Over a file called "Open Archive.TXT", i get "Open" as the output.
The name "Open Archive.TXT" will get split into separate arguments, so the first argument will be "Open". You should also get a dialog for "Archive.TXT".
but shouldn't the fileName="$arg" make it one file?
No. You use the "for arg do" syntax, which splits the command line into arguments using space as the delimiter.
Quote:
Originally Posted by kwanbis
I get: "Open Archive.TXT", the .EXT is not taken out.
AUGH! My bad. Use your original extension stripping code. I occasionally get "basename" confused with the DOS/Windows "splitpath" function. Most of the time, they do the same thing... unless there is an extension you want to remove.
Because a GUI does not (normally) have a terminal, GUIs that run command line utilities have nowhere to send the output. Thus the need for log files for scripts that will be run under the control of a GUI.
The same problem occurs with daemons (such as web servers) that close stdout, stderr, and stdin in the child after they fork. They have no terminal to which to send output, so they log everything to files. Thus the need for several different log files in the configuration for Apache (i.e. error.log, access.log, etc.).
That works fine, the only problem is that it is not real time. Unrar decompresses all the files, and then the progress works.
So i created a VERY BASIC Lazarus/FreePascal application, that reads all the input, and prints it to both, a memo, and a tpanel.
This is most of the code.
Code:
procedure TForm1.Memo1Enter(Sender: TObject);
var
fStdIO: TextFile;
sLinea: string;
begin
assignfile(fStdIO,''); reset(fStdIO); // open the stdin "file"
while not eof(fStdIO) do begin // while we are getting standard input ...
application.ProcessMessages; // process messages (paint the texts)
readln(fStdIO,sLinea); // read the a line
sLinea := StringReplace(sLinea, '', '', [rfReplaceAll, rfIgnoreCase]); // remove the strange unrar characters
sLinea := StringReplace(sLinea, ' ', ' ', [rfReplaceAll, rfIgnoreCase]); // remove double spaces
Memo1.Append(sLinea); // update the memo
Panel1.Caption := sLinea; // update the panel
end;
closefile(fStdIO); // close stdin "file"
Application.Terminate;
end;
So now i have a script to extract my RARs, that goes like this:
Code:
#!/bin/bash
for arg
do
pathName=`echo $NAUTILUS_SCRIPT_CURRENT_URI | sed -e 's|file:///|/|' -e 's|//|/|' -e 's|%20| |'`
fileName="$arg"
fullName=$pathName/$fileName
fileNoExt=${fileName%.*}
fullFolder=$pathName/$fileNoExt
~/xtractor/unrar e "$fullName" "$fullFolder/" | ~/xtractor/capturer
done
I still need to add something to check the returned value, and if it is ok, just close, if not, give an error message.
That works fine, the only problem is that it is not real time. Unrar decompresses all the files, and then the progress works.
I guess I was assuming you would change your script to be something like this
Code:
#!/bin/sh
(
unrar-command | sed -e 's/\([0-9]*\)%/\n\1\n/g'
) |
zenity --progress \
--title="Actualizando los registros del sistema" \
--text="Rastreando los registros de los correos..." \
--percentage=0
if [ "$?" = -1 ] ; then
zenity --error \
--text="Actualización cancelada."
fi
The sed expression should convert the output of the "unrar-command" to data that zenity understands. I created a proof of concept here using the following two scripts.
This first script simulates the output of the unrar command being processed into lines that zenity understands:
Code:
#!/bin/bash
# This simulates the output of the unrar command
exec 3<data
while read -u 3 line
do
echo $line | sed -e 's/\([0-9]*\)%/\n\1 #\n/g' | grep "#"
sleep 1 ;
done
This takes the output of the previous script and updates the progress bar of the zenity dialog:
My experiments show that you will need two scripts, one to run the command and convert the output, and one to display the zenity dialog. Trying to do the sed and grep in the zenity script causes the dialog to wait until the first script completes before it updates the progress bar, and then it jumps all the way to 100%.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.