Jump to content

cmd window text is it readable?


Go to solution Solved by FireFox,

Recommended Posts

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

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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

Link to comment
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
Link to comment
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

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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

Link to comment
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

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