Sign in to follow this  
Followers 0
Smyte

Help on extracting files using 7zip

8 posts in this topic

Hey, i'm new to the advanced features of autoit programming and my knowledge is basic at best but i've made use of the predefined functions to make a program which searches and pulls files from certain computers on a network.

Problem i'm facing now is some of the data is zipped using the .tar.bz2 compression format and i'm supposed to find a way to get my program to extract it. I've tried using some UDF's I searched but they didn't seem to work for me, even the examples provided inside weren't working(I assume it's a problem with the .dll's): '?do=embed' frameborder='0' data-embedContent>>

Then I stumbled across this line

$Extract = Run(@ScriptDir & '\7z.exe' & ' x "' & $Source & '" ' & "-y -o" & '"' & $Dest & '"', "", @SW_HIDE)

in this thread: '?do=embed' frameborder='0' data-embedContent>>

It dawned on me then that there's much more to the 'run' family of functions that I initially thought. Provided I had 7zip installed, I wouldn't have to externally run and compile into my exe the .dll file using autoit. Unfortunately the run code didn't run for me as well, even after changing @ScriptDIr to @ProgramfilesDir and changing from 7z.exe to 7zG.exe(And yes, i'm sure 7z is installed in my program files directory and has both those exe files.).

Will some of you pros here help a newbie like myself by explaining how to read and understand what was stated in the run? Where can I learn more about controlling programs this way without accessing their GUI's? The help file was useful but only partly, maybe because I don't know where to look.

Share this post


Link to post
Share on other sites



first, you don't have to have 7zip installed. you need only 7z.exe and 7z.dll both present in the same directory.

for explanation on the syntax of Run(), or any other function - use the help file, it's very very very good, and it should be your first place to look for help.

next, instead of using Run(), use RunWait(). this will return the exit code of the program being run, and that will give you another hint as to why it failed.

you can also describe your statement "the run code didn't run for me as well" in further details, i.e. what does happen, instead of what doesn't happen. help us help you!

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Thanks for the reply! When i used that section of code, declaring the variables as the zipfile location and destination directory, I got a return 0 and @error was set to 1 from my runwait. The help file's description of run/runwait speaks of run capturing streams of data and child processes but what I want to know is what the program reads from the line of code I posted earlier, and what form of syntax it's using - do most standalone exe programs read data fed to them using Run or Runwait similarly?

 

EDIT: Another example of code I previously searched up somewhere and edited based on my limited understanding, getting cmd to pipe a file dir to the location. This was simpler to understand and thus I could roughly understand what cmd was being told to do. Other programs don't seem to have reading resources as easily accessible as dos. Thus, I feel i'm missing out on some reading material somewhere.(It could be in the helpfile? But can you please direct me on where to look?)

 

$cmdstring = " /c cd P:\Backup && p: && dir >"&'"'&$destiloca&"\Dirfiles\Datalogbackupdir.txt"&'"'
RunWait(@COMSPEC & $cmdstring, "", @SW_Hide )
Edited by Smyte

Share this post


Link to post
Share on other sites

from the helpfile for RunWait():

Return Value Success: Returns the exit code of the program that was run. Failure: Returns 0 and sets @error to non-zero.  

you can conclude that your exe does not even run. error #1 usually means "file not found" (not always though). so i'd check thoroughly the paths and syntax passed to RunWait(). how?

1) first, enclose the @ScriptDir&'7z.exe' in double quotes, like this:

RunWait('"'&@ScriptDir & '\7z.exe"' & ' x "' & $Source & '" ' & "-y -o" & '"' & $Dest & '"', "", @SW_HIDE) 

2) replace the RunWait with ConsoleWrite (note: add &@CRLF and omit the 2nd and 3rd parameters):

ConsoleWrite('"'&@ScriptDir & '\7z.exe"' & ' x "' & $Source & '" ' & "-y -o" & '"' & $Dest & '"'&@CRLF)

when you run the script in SciTe, take a look at the output pane (under the editing pane). that line will put in there the string passed to Run, after the variables are replaced by real values. i think you'll find an extra or missing whitespace here or there.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Thanks a million my good man, that helped quite a bit, found why it wasn't running the .exe using ConsoleWrite. Was a careless path error and I replaced '7z.exe"' with '7-Zip7z.exe"'. Though, with the .tar.bz2  compression format I had to run the .exe on the archive twice. Well, as long as it works, that's enough for me! :D

I was wondering though if you could help enlighten me on what the program understands from this data which I just sent to it? What does 'x', '-y', and '-o' mean? I'm sure there's some documentation on that somewhere? Like, when running a command line of 'xcopy' or 'dir' in DOS, we have the different modes of operation like /ad, /y....etc. etc.(kinda like a function's flags)

"C:\Program Files (x86)\7-Zip\7z.exe" x "C:\Users\User1\Desktop\Project\A1921682113.tar.bz2" -y -o"C:\Users\User1\Desktop\Project"

Is there a standard among many programs? Would I be able to run that code directing it to Winrar instead? My initial question has been solved and I can get to work now but, just for the sake of learning I would really like to know about running and feeding commands to programs in the background.

EDIT: Perhaps a Mod who reads this could help me change this topic now to "Questions on how .exe's read lines from Run/Runwait"? Or maybe i'll just start a new topic and mark this solved.

Edited by Smyte

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Some forums don't allow bumping and/or doubleposting, but I didn't see anything forbidding it in the rules, so, umm.....

*BUMP*

Edited by Smyte

Share this post


Link to post
Share on other sites

Some forums don't allow bumping and/or doubleposting, but I didn't see anything forbidding it in the rules, so, umm.....

*BUMP*

 

They actually don't allow bumping. But you have asked some simple questions.

The syntax is fairly easy to find on the internet:

http://sevenzip.sourceforge.jp/chm/cmdline/switches/index.htm

-x = extract; -y = yes to message boxes; -o = output directory...

As for standards among zip programs, no there isn't. Each have their own syntax.

Your last question was a little puzzling. But if you mean to ask if you can use 7zip for .7z files and WinRAR for .rar files, then yes you can. You can use _PathSplit to find the extension and use a If/Else statement to open the different extensions with their respective programs.


RAID Calculator | Software Installer

The truth has been suppressed since the dawn of time.

Share this post


Link to post
Share on other sites

Your answers have answered my questions perfectly! :thumbsup: .

So just to clarify, I would only be able to use the 'Run' family of functions and send command lines like such to certain programs whose developers have created commandline versions of the programs? So i'm guessing this would be tougher and/or there would be another way to do it with programs like...MS powerpoint for example.

I only ask this because after reading through some UDF's such as: '?do=embed' frameborder='0' data-embedContent>>

Toady and most if not all UDF writers seem to deal with objects and COM to control the programs like the function below. Am I correct by saying I would have to look at the MSDN COM documentation to learn this?(it is a standard thing that is not exclusive to autoit programming anymore, right?)
 

Func _PPT_SlideCount($obj)
    If IsObj($obj) <> 1 Then 
        SetError(1)
        Return 0
    Else
        Return $obj.Slides.Count
    Endif
EndFunc

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0