Greenhorn Posted December 23, 2007 Posted December 23, 2007 Hi,I have a problem and don't know how to handle it.My created script works fine, but if I compile it, the exe fails ..., why !?I figured out where it stops and I have an sneaking suspicion, but I'm not sure about it.I try to run an external tool (UnRAR.exe) and use StdoutRead and StderrRead to get the state of UnRAR.Is it possible that it only works with the AutoIt Wrapper and not in a compiled script !?The Taskmanager displays that UnRAR.exe is running, but it doesn't do it's job !Just like I said: If I run the code as a script it works.Please help me, if somebody could !Here's the related code/function where the script stops if it's compiled:expandcollapse popupFunc _UnRAR_Archive($sArchiveDir, $sArchive, $sPassword = '', $sDirectory = '') If FileExists($sArchiveDir & '\' & $sArchive) Then TraySetToolTip('ExtRAR - Entpacke ' & $sArchive) Select Case $sPassword = '' And $sDirectory = '' $pidUnRAR = Run(@ScriptDir & '\UnRAR.exe x -o+ "' & $sArchiveDir & '\' & $sArchive & '"', $sArchiveDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) _Stream_Read($pidUnRAR) If @error = 3 Then Return SetError(1) ; Password required. Case $sPassword = '' And $sDirectory <> '' $pidUnRAR = Run(@ScriptDir & '\UnRAR.exe x -o+ "' & $sArchiveDir & '\' & $sArchive & '" "' & $sDirectory & '"', $sArchiveDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) _Stream_Read($pidUnRAR) If @error = 3 Then Return SetError(1) ; Password required. Case $sPassword <> '' And $sDirectory = '' $pidUnRAR = Run(@ScriptDir & '\UnRAR.exe x -o+ -p"' & $sPassword & '" "' & $sArchiveDir & '\' & $sArchive & '"', $sArchiveDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) _Stream_Read($pidUnRAR) If @error = 2 Then Return SetError(2) ; Password incorrect. Case $sPassword <> '' And $sDirectory <> '' $pidUnRAR = Run(@ScriptDir & '\UnRAR.exe x -o+ -p"' & $sPassword & '" "' & $sArchiveDir & '\' & $sArchive & '" "' & $sDirectory & '"', $sArchiveDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) _Stream_Read($pidUnRAR) If @error = 2 Then Return SetError(2) ; Password incorrect. EndSelect EndIf TraySetToolTip('ExtRAR') EndFunc ;==>_UnRAR_Archive Func _Stream_Read($PID) While 1 $line = StdoutRead($PID) If @error Then ExitLoop ElseIf StringInStr($line, 'No files to extract') Then ;Return SetError(1) ElseIf StringInStr($line, 'All OK') Then Return EndIf WEnd While 1 $line = StderrRead($PID) If @error Then ExitLoop ElseIf StringInStr($line, 'password incorrect') And Not StringInStr($line, 'Enter password (will not be echoed)') Then Return SetError(2) ElseIf StringInStr($line, 'Enter password (will not be echoed)') Then Return SetError(3) EndIf WEnd EndFunc ;==>_Stream_ReadGretzGreenhornp.s.: I wish you all a merry x-mas and a happy new year !!!
Greenhorn Posted December 23, 2007 Author Posted December 23, 2007 O.K., I figured out, that StderrRead is pausing the script, because there is nothing to read from StderrChild. What can I do to return if there is nothing to read from StderrChild ? The helpfile is not clear enough to me. I read about the "peek"-option, but don't understand how to use it. Could somebody give me an example and what it does, please ? Greetz
spyrorocks Posted December 23, 2007 Posted December 23, 2007 Hmmm... Func _Stream_Read($PID) While processexists($PID) $line = StdoutRead($PID) If @error Then ExitLoop ElseIf StringInStr($line, 'No files to extract') Then ;Return SetError(1) ElseIf StringInStr($line, 'password incorrect') And Not StringInStr($line, 'Enter password (will not be echoed)') Then Return SetError(2) ElseIf StringInStr($line, 'Enter password (will not be echoed)') Then Return SetError(3) ElseIf StringInStr($line, 'All OK') Then Return EndIf WEnd return -1 ;Value to return if nothing returned at all from the process EndFunc ;==>_Stream_Read Is that what you want? That might work for you. As soon as the process closes itself, it will stop reading. [center] My Projects: Online AutoIt Compiler - AutoForum - AutoGuestbook - AutoIt Web-based Auto Installer - Pure AutoIt Zipping Functions - ConfuseGen - MindReader - P2PChat[/center]
Greenhorn Posted December 23, 2007 Author Posted December 23, 2007 (edited) Hi spyrorocks, thx for your attention. I need both, StdoutRead and StderrRead to use. For example, if UnRAR.exe is listing the password-protected Archive succesfully there is no stream for StderrRead. And that's why my exe pauses. So, what can I do to prevent that ? If the password is wrong I need StderrRead to check it out. I hope you understand what I mean (sorry for my bad english) I tried it this way, but it also fails ... Func _Stream_Read($PID) While 1 $line = StdoutRead($PID) If @error Then ExitLoop ElseIf StringInStr($line, 'Archive ') Then ; don't work ! ProcessClose($PID) Return ElseIf StringInStr($line, 'No files to extract') Then ;Return SetError(1) ElseIf StringInStr($line, 'All OK') Then Return EndIf WEnd While 1 $line = StderrRead($PID) If @error Then ExitLoop ElseIf StringInStr($line, 'password incorrect') And Not StringInStr($line, 'Enter password (will not be echoed)') Then Return SetError(2) ElseIf StringInStr($line, 'Enter password (will not be echoed)') Then Return SetError(3) EndIf WEnd EndFunc ;==>_Stream_Read StdoutRead by succeeded l(list) parameter: Archive J:\Downloads\umpf.rar Name Size Packed Ratio Date Time Attr CRC Meth Ver ------------------------------------------------------------------------------- *ExtRAR.exe 632273 495088 78% 20-12-07 02:48 .....A. 9F74BC0B m5e 2.9 *Liesmich.txt 788 496 62% 19-12-07 06:02 .....A. D2142CB5 m5e 2.9 *PwdList.txt 68 64 94% 14-12-07 02:47 .....A. 17A09CC4 m5e 2.9 *StartLoad.exe 233963 226800 96% 19-12-07 05:55 .....A. FD65993F m5e 2.9 *UnRAR.exe 203264 91664 45% 22-05-07 10:59 .....A. 31152AC6 m5e 2.9 ExtRAR 0 0 0% 20-12-07 02:48 .D..... 00000000 m0 2.9 ------------------------------------------------------------------------------- 6 1070356 814112 76% StderrRead by no success: Encrypted file: CRC failed in license.rar (password incorrect ?) Edited December 23, 2007 by Greenhorn
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now