Sign in to follow this  
Followers 0
Chimaera

cmd window text is it readable?

13 posts in this topic

I have a function that tests an archive before extraction.

The test works fine except when the archive is passworded

The return codes don't exist for password needed, and plus it just sits there waiting for it to be inputted.

post-60350-0-33127000-1370803960_thumb.p

This is the offending section

I have been testing all the codes to see if any trigger on passwords but they dont :(

So can the cmd window be read? specifically the bit "Enter password <will not be echoed>"

Also the window will normally be hidden with @SW_HIDE so can it still be read then?

This is about the only way i can think of to determine that it hangs on a password unless someone has a better idea?

Btw the password will probably not be available to me so i only need it to throw an error if its passworded

Share this post


Link to post
Share on other sites



Hi,

Take a look at the StdoutRead function.

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

To extend the reply of FireFox a bit:

Replace RunWait with Run and set the flags to "BitOr($STDIN_CHILD, $STDOUT_CHILD).

Then use StdOutRead until you get the "Enter password" line. Then pass the password using StdInWrite.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I actually dont need the password at all

All i need to do is detect this text in the window "Enter password <will not be echoed>" and force an exit of the program with an error message

Func _Archive_Test()
    $aRarFile = _RecFileListToArray(@ScriptDir, "*.7z;*.001", 1, 0)
;~      _ArrayDisplay($aRarFile, ".Rar Files")
    If IsArray($aRarFile) Then
        For $i = 1 To $aRarFile[0]
            $test = Run(@ComSpec & ' /c ' & @TempDir & '\Sup\7z.exe' & ' t ' & '"' & $aRarFile[$i] & '"', "", @SW_SHOW,BitOr($STDIN_CHILD, $STDOUT_CHILD))
                MsgBox(64, "Rar Test", "Test = " & $test & " - " & "Error = " & @error)
            If $test = 2 Then
                MsgBox(64, "Archive Failure", "Archive Extraction Failed, Manual Intervention Needed")
                Exit
            EndIf
            While 1
                Local $sOutput = StdoutRead($test)
                If @error Then
                    MsgBox(64, "StdRead Error", "Text not available")
                    ExitLoop
                EndIf
            WEnd
                Local $aArray = StringSplit(StringTrimRight(StringStripCR($sOutput), StringLen(@LF)), @LF)
                If @error Then
                    MsgBox(4096, "", "It appears there was an error trying to find all the files in the current script directory.")
                Else
            $array = _ArrayDisplay($aArray)
                EndIf


;~          ElseIf $test = 1073741510 Then
;~              MsgBox(64, "Archive Failure 1 ", "Archive Extraction Failed, Possible Password")
;~          ElseIf $test = 7 Then
;~              MsgBox(64, "Archive Failure 7 ", "Archive Extraction Failed, Possible Password")
        Next
    EndIf
    Sleep(200)
EndFunc   ;==>_Archive_Test()

Ive got this so far but the cmd window is black with no text on it so i must have done something wrong

Ill try again tommoz

Share this post


Link to post
Share on other sites

It will be black, because stdout and stdin have been redirected to your program by the flags. Just use @SW_HIDE instead of @SW_SHOW so no cmd window will be shown at all. You also need to test within the loop. Here is an example using pause:

#include <Constants.au3>

Local $iPid = Run("cmd /c pause", @ScriptDir, @SW_HIDE, BitOR($STDIN_CHILD, $STDOUT_CHILD))

ProcessWait($iPid)

Local $sOutput = ""
While 1
    $sOutput = StdoutRead($iPid)
    If @error Then ExitLoop

    If MsgBox($MB_YESNO, Default, '"' & $sOutput & '"') = $IDYES Then
        StdinWrite($iPid, @LF)
    EndIf
WEnd

Share this post


Link to post
Share on other sites

Thx Guys

Doesn't seem that hard from your eg, i must admit the one in the helpfile is a bit Ott

Ive adapted yours into mine and it just hangs on the extraction task until i end it in task manager

Then i get the error message "Text not available"

Func _Archive_Test()
    $aRarFile = _RecFileListToArray(@ScriptDir, "*.7z;*.001", 1, 0)
;~      _ArrayDisplay($aRarFile, ".Rar Files")
    If IsArray($aRarFile) Then
        For $i = 1 To $aRarFile[0]
            $ArchiveTest = Run(@ComSpec & ' /c ' & @TempDir & '\Sup\7z.exe' & ' t ' & '"' & $aRarFile[$i] & '"', "", @SW_HIDE, BitOR($STDIN_CHILD, $STDOUT_CHILD))
;~          MsgBox(64, "Rar Test", "Test = " & $ArchiveTest & " - " & "Error = " & @error)

            ProcessWait($ArchiveTest)
            $sOutput = ""

            While 1
                $sOutput = StdoutRead($ArchiveTest)
                If @error Then
                    MsgBox(64, "StdRead Error", "Text not available")
                    ExitLoop
                EndIf
            WEnd
                If MsgBox($MB_YESNO, Default, '"' & $sOutput & '"') = $IDYES Then
                StdinWrite($sOutput, @LF)
                EndIf
;~          $aArray = MsgBox(64, "write test", StdinWrite($sOutput, @LF))
;~          If @error Then
;~              MsgBox(4096, "", "Error = " & @error)
;~          EndIf
        Next
    EndIf
    Sleep(200)
EndFunc   ;==>_Archive_Test

Ive tried to slim out the rubbish but it still isnt working like yours

Ill keep trying

Share this post


Link to post
Share on other sites

@error is set when EOF is reached (no more messages to read) and when a "real" error occurres.

Can you post the value of @error?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

If you know the extraction ending text then wait for it and exit the loop.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

Yes i do m8 its this

"Enter password <will not be echoed>"

Just to clarify im just trying to read the text to find the text above the cmd window halts on that text

Which i can then use to exit the script and notify the user he needs to sort out his files manually because they have a password set on them

Its basically an error check to see if a password exists thats all

Share this post


Link to post
Share on other sites

I don't really understand what's the problem  :ermm:

$sOutput = StdoutRead($ArchiveTest)
If @error Or StringInStr($sOutput, "Enter password", 2) > 0 Then ExitLoop

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

Using FireFox excellent suggestion i ended up with this

ProcessWait($ArchiveTest)
            $sOutput = ""
            While 1
                $sOutput = StdoutRead($ArchiveTest)
                If StringInStr($sOutput, "Enter password", 2) > 0 Then
                    MsgBox(64, "Password Error", "Archive Is Passworded")
                    Exit
                ElseIf StringInStr($sOutput, "Error:", 2) > 0 Then
                    MsgBox(64, "Archive Error", "Archive Extraction Failed")
                    Exit
                EndIf
            WEnd

Many thanks guys

Share this post


Link to post
Share on other sites

ah :) I'm glad you got it working ;)


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

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