Jump to content

7zip script using Run/RunWait does not work


sundar
 Share

Recommended Posts

I am trying to extract certain files fom an archive using 7zip command line application. So i used this command to extract it and kept 7zip in script directory.

Run(@ScriptDir & '\7z.exe' & '"' & 'x' & '"' & 'E:\archive.zip' & '"' & '-o' & 'E:\' & '"' & 'file.txt' & '"' & '-r', " ", @SW_HIDE)

The actual command for extratcing particular file from archive is

7z x archive.zip -oc:\soft filename.txt -r

After running aboveAutoIt code it does not show any error and no eatraction is taking place. I tried it from cmd/console and it works fine. Am i missing something in the code above?

Link to comment
Share on other sites

I had this lying around >>

Func _7Zip_Extract($sZipFile, $sDestinationFolder = @ScriptDir, $sPassword = "")
If FileExists($sZipFile) = 0 Then
Return SetError(1, 0, 0)
EndIf
If StringRight($sDestinationFolder, 1) <> "\" Then
$sDestinationFolder &= "\"
EndIf
If FileExists($sDestinationFolder) = 0 Then
DirCreate($sDestinationFolder)
EndIf
If $sPassword <> "" Then
$sPassword = "-p" & '"' & $sPassword & '" '
EndIf
If FileExists(@ScriptDir & "\" & "7za.exe") = 0 Then
FileInstall("7za.exe", @ScriptDir & "\" & "7za.exe", 0)
EndIf
Return RunWait('7za.exe' & ' x "' & $sZipFile & '" ' & $sPassword & "-y -o" & '"' & $sDestinationFolder & '"', "", @SW_HIDE)
EndFunc ;==>_7Zip_Extract

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Thank you for the quick reply. I got this function from this forum and tried to modify according to my need. But instead of extracting single file it created file.tx tfolder in the destination folder and extracted allfiles in to it. Here is the modified line from the function.

Return RunWait('7za.exe' & ' x "' & $sZipFile & '" ' & $sPassword & "-o" & $sDestinationFolder & "file.txt" & "-r" & '"', "", @SW_HIDE)
Edited by sundar
Link to comment
Share on other sites

Thank you for the quick reply. I got this function from this forum and tried to modify according to my need. But instead of extracting single file it created file.tx tfolder in the destination folder and extracted allfiles in to it. Here is the modified line from the function.

Return RunWait('7za.exe' & ' x "' & $sZipFile & '" ' & $sPassword & "-o" & $sDestinationFolder & "file.txt" & "-r" & '"', "", @SW_HIDE)

*facepalm* That's because you're telling it to create the folder "file.txt"

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Link to comment
Share on other sites

What's wrong with using my function?

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

What's wrong with using my function?

Your function is absolutily fine. It did not work after i changed it.

*facepalm* That's because you're telling it to create the folder "file.txt"

Thanks for pointing out the mistake. I have solved it by using below command...

Return RunWait('7z.exe' & ' x "' & $7z_File & '" ' & $7z_Password & "-y -o" & $7z_Folder & ' file.txt"' & '" ' & "-r" & '"', "", @SW_HIDE)
Link to comment
Share on other sites

  • 1 year later...

Could I get some help on this same topic? This command works fine from the command prompt:

C:7z x "C:WindowsTempSep32bitdesktopx32.zip" -y > nul -o"C:Windowstempsep32bit"

I tell 7zip where the file is, extract it silently and place it in this location....Works fine

AutoIT script line:

Run('C:Program files7zip7z' & ' x "' & $7z_File &'" "-y -o > null" "'& $7z_Folder)

$7z_File = C:WindowsTempSep32bitdesktopx32.zip

$7z_Folder = C:WindowsTempSep32bit

Thanks for any help on this.

Link to comment
Share on other sites

Your quotes are wrong, and your command line is different in the script than it is in the command line.

Run('C:Program files7zip7z x "' & $7z_File &' -y > nul -o"'& $7z_Folder & '"')

This will give you the exact same command as your command line, if your first example is wrong, so is this one.

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Thank you for responding but all I get is a command prompt flash and nothing happens. Here is my code and I have alot rem'd out so I can test this faster.

;Commands for the progress bar and menu
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <SendMessage.au3> ;Needed for _SendMessage function.
#include <ProgressConstants.au3>

;Folder locations for each product to be copied too before running the application.
Local $sFldr32 = "C:Program Files (x86)SymantecSymantec Endpoint Protection"
Local $sFldr64 = "C:WindowsSysWOW64"
Local $sFldrSep = "C:WindowsTempSep"
Local $sSep32 = "C:WindowsTempSep32bit"
Local $sSep64 = "C:WindowsTempSep64bit"
Local $7z_File = "C:WindowsTempSEPDesktopx32.zip"
Local $7z_Folder = "C:WindowsTempSEP32bit"
Local $7z_7zip = "C:Program Files7zip"
;Folder creations for each product to install from

;File copy section: Each Application is taken from the source and copied to the folders created
;Local $a = True
;If $sSep32 = True Then FileInstall("I:SEPDesktopx32.zip", "C:WindowsTempSEP32bitDesktopx32.zip")
;Local $b = True
;If $sSep64 = True Then FileInstall("I:SEPDesktopx64.zip", "C:WindowsTempSEP64bitDesktopx64.zip")
;If $sSep32 = True Then FileInstall("I:SEPInstall.bat", "C:WindowsTempSEP32bitInstall.bat")
#cs
;SplashScreen while SEPTool runs
$hProgressSplash = _SplashTextProgress("Please Wait. This Window Will Close Automatically.")
Func _SplashTextProgress($sText) ;Creates a Splash Text Screen with a progress bar.
SplashOff() ;Turn previous splash text screens off.
$hSplash = GUICreate("", 500, 400, -1, -1, BitOR($WS_POPUP, $WS_BORDER), BitOR($WS_EX_TOPMOST, $WS_EX_WINDOWEDGE, $WS_EX_TOOLWINDOW))
;~ $iProgressBar = GUICtrlCreateProgress(100, 325, 305, 25, $PBS_SMOOTH)
$iProgressBar = GUICtrlCreateProgress(100, 325, 305, 25, $PBS_MARQUEE) ;A Marquee progress bar.
_SendMessage(GUICtrlGetHandle(-1), $PBM_SETMARQUEE, True, 80) ;last parameter is update time in ms. Sends message to run the Marquee progress bar.
$iMessage = GUICtrlCreateLabel($sText, 0, 100, 500, 200, $SS_CENTER)
GUICtrlSetFont(-1, 16, 400, 0, "Courier New")
GUISetState(@SW_SHOW)
Return SetExtended($iProgressBar, $hSplash)
EndFunc ;==>_SplashTextProgress
#CE

;Sleep(5000)

;If FileExists("C:WindowsSysWOW64CMD.exe") Then
Run('C:Program files7zip7z x "' & $7z_File &' -y > nul -o"'& $7z_Folder & '"')
; Sleep(20000)
;Else
;Run("C:Program files7zip7z" x "C:WindowsTempSEP32bitDesktopx32.zip" -y > nul -o"C:WindowsTempSEP32bit")
; Sleep(20000)
; EndIf
#cs
If FileExists("C:WindowsSysWOW64CMD.exe") Then
Run("C:WindowsTempSep64bitSep64.msi /qb /l*v REBOOT=ReallySuppress IDCENABLE=0")
Else
Run("C:WindowsTempSep32bitSep.msi /qb /l*v REBOOT=ReallySuppress IDCENABLE=0")
Sleep(10000)
EndIf
#ce

I retested the command line I sent in my last post and it worked fine in a Command Prompt window.

Thanks

Edited by RBrown1375
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...