Jump to content

Reading StdOut for 7-Zip Console...


Recommended Posts

Hi all. I'm sure i'm missing something here... I'm trying to read the console window text of the commandline / console version of 7-Zip so I can parse it to provide some feedback for long compression loops... all I get is a blank 7-Zip console window and nothing in tray information...

#include <Constants.au3>
Local $line
Local $outfile = @ScriptDir & "\test.7z"
Local $infile = @ScriptDir & "\test.iso";for example
$zip = Run(@ScriptDir & "\7za.exe a -t7z -mx9 " & Chr(34) & $outfile & Chr(34) & " " & Chr(34) & $infile & Chr(34),"",@SW_SHOW,$STDERR_CHILD + $STDOUT_CHILD)
While 1
    $line &= StdoutRead($zip,False)
    If @error Then ExitLoop
    TrayTip("",$line,5)
Wend

Any help appreciated.

Link to comment
Share on other sites

Hi all. I'm sure i'm missing something here... I'm trying to read the console window text of the commandline / console version of 7-Zip so I can parse it to provide some feedback for long compression loops... all I get is a blank 7-Zip console window and nothing in tray information...

#include <Constants.au3>
Local $line
Local $outfile = @ScriptDir & "\test.7z"
Local $infile = @ScriptDir & "\test.iso";for example
$zip = Run(@ScriptDir & "\7za.exe a -t7z -mx9 " & Chr(34) & $outfile & Chr(34) & " " & Chr(34) & $infile & Chr(34),"",@SW_SHOW,$STDERR_CHILD + $STDOUT_CHILD)
While 1
    $line &= StdoutRead($zip,False)
    If @error Then ExitLoop
    TrayTip("",$line,5)
Wend

Any help appreciated.

Nothing wrong with your StdOutRead(). The TrayTip() is awkward since it gets updated so rapidly, but it should work. I did this to test the command line string and to see the output for myself:
#include <Constants.au3>

Local $s7zDir = "C:\Program Files\7-zip"
Local $s7za = $s7zDir & "\7za.exe"
Local $outfile = $s7zDir & "\test.7z"
Local $infile = $s7zDir & "\readme.txt"
Local $sTest = $s7za & ' a -t7z -mx9 "' & $outfile & '" "' & $infile & '"'
MsgBox(64, "Test", $sTest)

Local $line
$zip = Run($sTest, "", @SW_SHOW, $STDERR_MERGED)
While 1
    $line &= StdoutRead($zip, False)
    If @error Then ExitLoop
    TrayTip("", $line, 5)
WEnd
MsgBox(64, "Done", $line)

The Chr(34) isn't necessary, but it should have worked too.

I don't see the problem.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

@PsaltyDS - Thanks for reply. I guess the console doesn't use standard I/O - I can't get any information from it... To be honest, I didn't try to see if it captured output on completion,as I am trying to capture text during compression to provide feedback for longer processes (i.e a progressbar). I can't seem to capture the text at all... I even tried LazyCat's DConsole reader code - nothing...

I'll keep fiddling and see.

Link to comment
Share on other sites

  • Moderators

@PsaltyDS - Thanks for reply. I guess the console doesn't use standard I/O - I can't get any information from it... To be honest, I didn't try to see if it captured output on completion,as I am trying to capture text during compression to provide feedback for longer processes (i.e a progressbar). I can't seem to capture the text at all... I even tried LazyCat's DConsole reader code - nothing...

I'll keep fiddling and see.

I'm pretty sure Valik did that here: http://www.autoitscript.com/forum/index.ph...st&p=527810

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

A while ago i made the following script, just to check the same issue, but somehow now it's broken for 7zip, but it's seems that console version of Rar.exe works fine...

#include <GuiStatusBar.au3>
#include <GUIConstantsEx.au3>
#include <Constants.au3>
#include <EditConstants.au3>
#include <ComboConstants.au3>
#include <Timers.au3>
#include <Array.au3>

Global $Default_Archive_Name = "Archive.zip"
Global $sStdOut_Read = "", $sRaw_StdOut_Read

$hGUI = GUICreate("Add files to archive GUI", 500, 300)

GUICtrlCreateLabel("Archivator:", 20, 5, -1, 15)
$Archivator_Combo = GUICtrlCreateCombo("", 20, 20, 460, 20, $CBS_DROPDOWNLIST)
_SetArchivator_Proc()

$ProgressBar = GUICtrlCreateProgress(20, 45, 460, 20)
$ProgressStatusBar = _GUICtrlStatusBar_Create($hGUI, 0, "")
_GUICtrlStatusBar_SetSimple($ProgressStatusBar)

$Status_Edit = GUICtrlCreateEdit("", 20, 110, 460, 160, BitOr($GUI_SS_DEFAULT_EDIT, $ES_READONLY))

$Add_Button = GUICtrlCreateButton("Add file(s)/folder...", 200, 80, 110, 20)

$Context_Menu = GUICtrlCreateContextMenu()
$AddFiles_MenuItem = GUICtrlCreateMenuitem("Add files...", $Context_Menu)
$AddFolder_MenuItem = GUICtrlCreateMenuitem("Add folder...", $Context_Menu)

GUISetState()

While 1
    $nMsg = GUIGetMsg()
    
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Add_Button
            ShowMenu($hGUI, $Add_Button, $Context_Menu)
        Case $AddFiles_MenuItem
            $sOpenFiles = FileOpenDialog("Add files to archive", "", "All Files (*.*)", 4, "", $hGUI)
            
            If Not @error Then
                If StringInStr($sOpenFiles, "|") Then
                    $sOpenFiles = '"' & StringReplace(StringReplace($sOpenFiles, @WorkingDir & "|", ""), '|', '" "') & '"'
                Else
                    $sOpenFiles = '"' & StringStripCR($sOpenFiles) & '"'
                EndIf
                
                $Archivator_Path = GUICtrlRead($Archivator_Combo)
                
                $Default_Archive_Name = "Archive.zip"
                If StringInStr($Archivator_Path, "rar.exe") Then $Default_Archive_Name = "Archive.rar"
                
                $sArchiveName_Input = InputBox("Archive Name", _
                    "Type archive name that files will be added into it:", $Default_Archive_Name, '', 280, 150, -1, -1, -1, $hGUI)
                
                If $sArchiveName_Input <> "" Then
                    $sArchiveName_Input = StringRegExpReplace($sArchiveName_Input, '["?:|/\\*<>]', '_')
                    
                    If StringInStr($Archivator_Path, "rar.exe") Then
                        $iPid = Run($Archivator_Path & ' a -ep1 "' & _
                            @WorkingDir & "\" & $sArchiveName_Input & '" ' & $sOpenFiles, @WorkingDir, @SW_HIDE, 2 + 4)
                    Else
                        $iPid = Run($Archivator_Path & ' a "' & _
                            @WorkingDir & "\" & $sArchiveName_Input & '" ' & $sOpenFiles, @WorkingDir, @SW_HIDE, 2 + 4)
                    EndIf
                    
                    GUICtrlSetData($Add_Button, "Abort")
                    AddFiles_Proc($iPid)
                EndIf
            EndIf
        Case $AddFolder_MenuItem
            $sOpenFolder = FileSelectFolder("Add directory to archive...", 0, 0, "", $hGUI)
            
            If Not @error Then
                $Archivator_Path = GUICtrlRead($Archivator_Combo)
                
                $Default_Archive_Name = "Archive.zip"
                If StringInStr($Archivator_Path, "rar.exe") Then $Default_Archive_Name = "Archive.rar"
                
                $sArchiveName_Input = InputBox("Archive Name", _
                    "Type archive name that files will be added into it:", $Default_Archive_Name, '', 280, 150, -1, -1, -1, $hGUI)
                
                If $sArchiveName_Input <> "" Then
                    $sArchiveName_Input = StringRegExpReplace($sArchiveName_Input, '["?:|/\\*<>]', '_')
                    
                    If StringInStr($Archivator_Path, "rar.exe") Then
                        $iPid = Run($Archivator_Path & ' a -ep1 "' & StringTrimRight($sOpenFolder, _
                            StringLen(StringRegExpReplace($sOpenFolder, "^.*\\", ""))) & $sArchiveName_Input & '" "' & _
                            $sOpenFolder & '"', "", @SW_HIDE, 2 + 4)
                    Else
                        $iPid = Run($Archivator_Path & ' a "' & StringTrimRight($sOpenFolder, _
                            StringLen(StringRegExpReplace($sOpenFolder, "^.*\\", ""))) & $sArchiveName_Input & '" "' & _
                            $sOpenFolder & '"', "", @SW_HIDE, 2 + 4)
                    EndIf
                    
                    GUICtrlSetData($Add_Button, "Abort")
                    AddFiles_Proc($iPid)
                EndIf
            EndIf
    EndSwitch
WEnd

Func AddFiles_Proc($iPid)
    Local $hTimer_Proc = _Timer_SetTimer($hGUI, 1, "_SetProgress_Proc")
    GUICtrlSetData($Status_Edit, "")
    
    While ProcessExists($iPid)
        $nMsg = GUIGetMsg()
        $sStdOut_Read = StdoutRead($iPid)
        If @error Then ExitLoop
        
        $sRaw_StdOut_Read &= $sStdOut_Read
        
        If $nMsg = $Add_Button Then
            ProcessClose($iPid)
            GUICtrlSetData($ProgressBar, 0)
            ExitLoop
        EndIf
    WEnd
    
    _Timer_KillTimer($hGUI, $hTimer_Proc)
    
    GUICtrlSetData($Add_Button, "Add file(s)/folder...")
    Local $sDoneMsg = "Done!", $sErrMsg = ""
    
    If StringInStr($sStdOut_Read, "Warning") Or StringInStr($sStdOut_Read, "Error") Then
        $sStdOut_Read = StringStripWS($sStdOut_Read, 3)
        GUICtrlSetData($Status_Edit, $sStdOut_Read)
        
        If StringInStr($sStdOut_Read, "Warning") Then $sErrMsg = StringRegExpReplace($sStdOut_Read, "(?i)(?s).*?(Warning.*?)", "\1")
        If StringInStr($sStdOut_Read, "Error") Then $sErrMsg = StringRegExpReplace($sStdOut_Read, "(?i)(?s).*?(Error.*?)", "\1")
        
        $sDoneMsg = StringFormat("Done! (%s)", StringStripWS($sErrMsg, 3))
    EndIf
    
    _GUICtrlStatusBar_SetText($ProgressStatusBar, $sDoneMsg, 255)
EndFunc

Func _SetProgress_Proc($hWnd, $nMsg, $iIDTimer, $dwTime)
    Local $iProgress = _StringStripWords($sStdOut_Read)
    
    If $iProgress <> "" Then GUICtrlSetData($ProgressBar, $iProgress)
    
    If $sStdOut_Read <> "" Then
        GUICtrlSetData($Status_Edit, $sStdOut_Read & @CRLF, 1)
        
        _GUICtrlStatusBar_SetText($ProgressStatusBar, _
            StringFormat("Add files process... %s", StringRegExpReplace($sStdOut_Read, "\A(.*?\d+%.*?)[\s|\t|\n|\r].*", "\1")), 255)
    EndIf
EndFunc

Func _SetArchivator_Proc()
    Local $s7Zip_Archivator = RegRead("HKEY_CURRENT_USER\Software\7-Zip", "Path") & "\7z.exe"
    If FileExists($s7Zip_Archivator) Then GUICtrlSetData($Archivator_Combo, $s7Zip_Archivator, $s7Zip_Archivator)
    
    Local $sRar_Archivator = StringRegExpReplace(RegRead("HKEY_CLASSES_ROOT\.rar\ShellNew", "FileName"), _
        "\\[^\\]*$", "") & "\rar.exe"
    If FileExists($sRar_Archivator) Then GUICtrlSetData($Archivator_Combo, $sRar_Archivator, $sRar_Archivator)
    
    If Not FileExists($s7Zip_Archivator) And  Not FileExists($sRar_Archivator) Then
        MsgBox(16, "Error!", "Archiving Program was not found." & @LF & @LF & "OK --> EXIT")
        Exit
    EndIf
EndFunc

Func _StringStripWords($sString, $iRetType=0)
    $sString = StringRegExpReplace($sString, '[^0-9]', '')
    If $iRetType = 1 Then Return StringSplit($sString, "")
    Return $sString
EndFunc

Func ShowMenu($hWnd, $CtrlID, $nContextID)
    Local $hMenu = GUICtrlGetHandle($nContextID)
    
    $arPos = ControlGetPos($hWnd, "", $CtrlID)
    
    Local $x = $arPos[0]
    Local $y = $arPos[1] + $arPos[3]
    
    ClientToScreen($hWnd, $x, $y)
    DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $x, "int", $y, "hwnd", $hWnd, "ptr", 0)
EndFunc

Func ClientToScreen($hWnd, ByRef $x, ByRef $y)
    Local $stPoint = DllStructCreate("int;int")
    
    DllStructSetData($stPoint, 1, $x)
    DllStructSetData($stPoint, 2, $y)

    DllCall("user32.dll", "int", "ClientToScreen", "hwnd", $hWnd, "ptr", DllStructGetPtr($stPoint))
    
    $x = DllStructGetData($stPoint, 1)
    $y = DllStructGetData($stPoint, 2)
    ; release Struct not really needed as it is a local 
    $stPoint = 0
EndFunc

:)

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

  • 3 years later...

I'm pretty sure Valik did that here: http://www.autoitscript.com/forum/index.ph...st&p=527810

Is this Link broken? Instead of any thread only a page with error appears:

An Error Occurred

Sorry, an error occurred. If you are unsure on how to use a feature, or don't know why you got this error message, try looking through the help files for more information.

[#103139] You do not have permission to view this forum.

Link to comment
Share on other sites

That links to the chat forum, which I believe you need 5 posts before you can access it. You now have 5 posts so try the link again and see if you're able to see it now.

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

  • 11 months later...

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...