johnmcloud Posted February 14, 2012 Share Posted February 14, 2012 (edited) Hi guys, i have a little problem to set the @error to _StringBetween The script: While 1 $line = StdoutRead($CMDCommand) If @error Then ExitLoop $tmp = _StringBetween($line, "] ", '%') If Not @error Then $replace = StringReplace($tmp[0], "%", "") MsgBox(64, "Test", "string found") EndIf WEnd This script working, but i need to set something if the string don't match. I have try like this: While 1 $line = StdoutRead($CMDCommand) If @error Then ExitLoop $tmp = _StringBetween($line, "] ", '%') If Not @error Then $replace = StringReplace($tmp[0], "%", "") MsgBox(64, "Test", "string found") Else MsgBox(17, "Test", "no string found") EndIf WEnd But i have everytime the error MsgBox also if the string is found. Some advice? Thanks for support Edited February 14, 2012 by johnmcloud Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 14, 2012 Moderators Share Posted February 14, 2012 johnmcloud,Your logic works for me. In this example I have just reversed the order of the test - why use Not if you do not have to? #include <String.au3> Global $aLines[3] = ["works] 34%", "Fails", "works] 57%"] For $i = 0 To 2 $sLine = $aLines[$i] $aFound = _StringBetween($sLine, "] ", '%') If @error Then MsgBox(0, "Test " & $i, "no string found") Else $sReplace = StringReplace($aFound[0], "%", "") MsgBox(0, "Test " & $i, "string found" & @CRLF & $aFound[0] & @CRLF & $sReplace) EndIf NextAnd why do you use the StringReplace line? As you can see the & does not form part of the string returned by _StringBetween. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
johnmcloud Posted February 14, 2012 Author Share Posted February 14, 2012 (edited) Melba, also with your example i have @error MsgBox and working at the same time... Test 0no string foundTest 1no string foundTest 2no string foundTest 0no string foundTest 1no string foundTest 2no string foundTest 0no string foundTest And this is the stdoutread at first check: [download] 0.0% of 3.52M at ---b/s ETA --:-- [download] 0.1% of 3.52M at ---b/s ETA --:-- [download] 0.2% of 3.52M at 116.67k/s ETA 00:30 [download] 0.4% of 3.52M at 187.50k/s ETA 00:19 [download] 0.9% of 3.52M at 221.43k/s ETA 00:16 [download] 1.7% of 3.52M at 273.91k/s ETA 00:12 [download] 3.5% of 3.52M at 352.78k/s ETA 00:09 [download] 7.1% of 3.52M at 425.00k/s ETA 00:07 [download] 14.2% of 3.52M at 468.38k/s ETA 00:06 I have this only if file is valid, for this i want to set an @error if don't find string ] to % Thanks for help Edited February 14, 2012 by johnmcloud Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 14, 2012 Moderators Share Posted February 14, 2012 johnmcloud,So when you run that exact code I posted you it always says it found "no string"? Have you recoded your _StringBetween function at all? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
johnmcloud Posted February 14, 2012 Author Share Posted February 14, 2012 (edited) Yes, your code: #include <String.au3> Global $aLines[3] = ["works] 34%", "Fails", "works] 57%"] For $i = 0 To 2 $sLine = $aLines[$i] $aFound = _StringBetween($sLine, "] ", '%') If @error Then ConsoleWrite("Test " & $i & "no string found") Else $sReplace = StringReplace($aFound[0], "%", "") ConsoleWrite("Test " & $i & "string found" & @CRLF & $aFound[0] & @CRLF & $sReplace) EndIf Next The result: Test 0string found 34 34Test 1no string foundTest 2string found 57 57+>10:22:19 AutoIT3.exe ended.rc:0 >Exit code: 0 Time: 1.947 Edited February 14, 2012 by johnmcloud Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 14, 2012 Moderators Share Posted February 14, 2012 johnmcloud, Using your data also works fine for me: #include <String.au3> Global $aLines[11] = ["[download] 0.0% of 3.52M at ---b/s ETA --:--", _ "[download] 0.1% of 3.52M at ---b/s ETA --:--", _ "[download] 0.2% of 3.52M at 116.67k/s ETA 00:30", _ "[download] 0.4% of 3.52M at 187.50k/s ETA 00:19", _ "fred", _ "[download] 0.9% of 3.52M at 221.43k/s ETA 00:16", _ "[download] 1.7% of 3.52M at 273.91k/s ETA 00:12", _ "[download] 3.5% of 3.52M at 352.78k/s ETA 00:09", _ "fred", _ "[download] 7.1% of 3.52M at 425.00k/s ETA 00:07", _ "[download] 14.2% of 3.52M at 468.38k/s ETA 00:06"] For $i = 0 To UBound($aLines) - 1 $sLine = $aLines[$i] $aFound = _StringBetween($sLine, "] ", '%') If @error Then ConsoleWrite($i & " - " & "No string" & @CRLF) ;MsgBox(0, "Test " & $i, "no string found") Else ConsoleWrite($i & " - " & $aFound[0] & @CRLF) ;MsgBox(0, "Test " & $i, "string found" & @CRLF & $aFound[0] & @CRLF & $sReplace) EndIf Next Result: 0 - 0.0 1 - 0.1 2 - 0.2 3 - 0.4 4 - No string 5 - 0.9 6 - 1.7 7 - 3.5 8 - No string 9 - 7.1 10 - 14.2 How about when you run it? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
johnmcloud Posted February 14, 2012 Author Share Posted February 14, 2012 (edited) $aLines = StdoutRead($CMDCommand) For $i = 0 To UBound($aLines) - 1 $sLine = $aLines[$i] Global $aFound = _StringBetween($sLine, "] ", '%') If @error Then ConsoleWrite($i & " - " & "No string" & @CRLF) ;MsgBox(0, "Test " & $i, "no string found") Else ConsoleWrite($i & " - " & $aFound[0] & @CRLF) ;MsgBox(0, "Test " & $i, "string found" & @CRLF & $aFound[0] & @CRLF & $sReplace) EndIf Next If $fInterrupt <> 0 Then ; Stop Loop Stop_Download() MsgBox(16, "Information", "Interrupt") Return EndIf EndFunc Seems not working on my script, you script working. I'm sure something miss, what i'm doing wrong? Edited February 14, 2012 by johnmcloud Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 14, 2012 Moderators Share Posted February 14, 2012 johnmcloud,That will not work as you do not get an array returned from StdoutRead. I only used the For...Next loop as an example. Perhaps this:Global $aFound While 1 $line = StdoutRead($CMDCommand) If @error Then ExitLoop $aFound = _StringBetween($sLine, "] ", '%') If @error Then ConsoleWrite($i & " - " & "No string" & @CRLF) ;MsgBox(0, "Test " & $i, "no string found") Else ConsoleWrite($i & " - " & $aFound[0] & @CRLF) ;MsgBox(0, "Test " & $i, "string found" & @CRLF & $aFound[0] & @CRLF & $sReplace) EndIf If $fInterrupt <> 0 Then ; Stop Loop Stop_Download() MsgBox(16, "Information", "Interrupt") Return EndIf WEndAny luck? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
johnmcloud Posted February 14, 2012 Author Share Posted February 14, 2012 No luck, man. I have also the error: - No string - No string - 100.0 I don't know how to do Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 14, 2012 Moderators Share Posted February 14, 2012 johnmcloud, Run this so we can see exactly what you actually get from the stream: Global $aFound While 1 $line = StdoutRead($CMDCommand) If @error Then ExitLoop $aFound = _StringBetween($sLine, "] ", '%') If @error Then ConsoleWrite($i & " - " & $sLine & " = " & "No string" & @CRLF) ;MsgBox(0, "Test " & $i, "no string found") Else ConsoleWrite($i & " - " & $sLine & " = " & $aFound[0] & @CRLF) ;MsgBox(0, "Test " & $i, "string found" & @CRLF & $aFound[0] & @CRLF & $sReplace) EndIf If $fInterrupt <> 0 Then ; Stop Loop Stop_Download() MsgBox(16, "Information", "Interrupt") Return EndIf WEnd Now we will check exactly what you are getting and whether the function should return something. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
johnmcloud Posted February 14, 2012 Author Share Posted February 14, 2012 (edited) An infinite number of - NoString P.S I have error for $i, so i have removed them Normal working output: [software] Setting language [software] ktHwS3yUr4U: Downloading video webpage [software] ktHwS3yUr4U: Downloading video info webpage [software] ktHwS3yUr4U: Extracting video information [download] Destination: ktHwS3yUr4U.mp4 [download] 0.0% of 3.52M at 90.91k/s ETA 00:39 [download] 0.1% of 3.52M at 272.72k/s ETA 00:13 [download] 0.2% of 3.52M at 98.59k/s ETA 00:36 [download] 0.9% of 3.52M at 205.30k/s ETA 00:17 When don't work [software] Setting language [software] asdsdadsa: Downloading video webpage ERROR: unable to download video webpage: HTTP Error 404: Not Found Edited February 14, 2012 by johnmcloud Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 14, 2012 Moderators Share Posted February 14, 2012 johnmcloud,Sorry about the $i - but as I cannot test for the same input as you.... What did you actually get in the console? The output line should include the actual line we are using as well as "No string". If there was nothing in the line then you cannot expect to find anything within it. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
johnmcloud Posted February 14, 2012 Author Share Posted February 14, 2012 (edited) I'll post the entire code, so you can test it, if you want: "Script is broken, i'll post only if full working" Mine is only a test, i have many other command-line software, the principle is always the same Edited February 14, 2012 by johnmcloud Link to comment Share on other sites More sharing options...
johnmcloud Posted February 14, 2012 Author Share Posted February 14, 2012 (edited) Guys, i think i can figure out how resolve the problem, but i need another little information. I can't write on a txt the log of a stderrRead, what is the problem? Local $txt = @WorkingDir & "log.txt" Local $txtread = FileRead($ini) $Error = StderrRead($CMDCommand) $logCreate = FileOpen($txt, 2) FileWrite($logCreate, $Error) FileClose($txt) The file is empty, but on consolewrite i see a result, so what is my error? Thanks for support EDIT: Solved adding a Dim on all $var Edited February 14, 2012 by johnmcloud Link to comment Share on other sites More sharing options...
johnmcloud Posted February 14, 2012 Author Share Posted February 14, 2012 I'have try to add a MsgBox, after 3-4 empty messages i have the console text. I have try to add a _FileWriteFromArray but the log is always empty... Please, some advice? Thanks for all. Link to comment Share on other sites More sharing options...
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