Sign in to follow this  
Followers 0
johnmcloud

[SOLVED] _StringBetween @error

15 posts in this topic

#1 ·  Posted (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 by johnmcloud

Share this post


Link to post
Share on other sites



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
Next

And 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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (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 by johnmcloud

Share this post


Link to post
Share on other sites

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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (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 by johnmcloud

Share this post


Link to post
Share on other sites

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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (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 by johnmcloud

Share this post


Link to post
Share on other sites

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
    
WEnd

Any luck? :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

No luck, man. I have also the error:

- No string
- No string
- 100.0

I don't know how to do :)

Share this post


Link to post
Share on other sites

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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#11 ·  Posted (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 by johnmcloud

Share this post


Link to post
Share on other sites

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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#13 ·  Posted (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 by johnmcloud

Share this post


Link to post
Share on other sites

#14 ·  Posted (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 by johnmcloud

Share this post


Link to post
Share on other sites

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.

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

  • Similar Content

    • ruslanas402
      By ruslanas402
      Why doesn't print the output??

      #include <String.au3> Global $x = 'gdsgklj fsdl dasfgh fsfef ghterfsd kia gdfhgfgdsgklj fsdl dasfgh fsfef' $z = _StringBetween($x, 'fsdl', 'kia') ConsoleWrite($z & @CRLF)
      Shouldn't it be
      dasfgh fsfef ghterfsd   instead of nothing?
       
    • 6105
      By 6105
      Hi, have here some alternative method to count rows..

      I can't use StringSplit coz array is already buided with _StringBetween, some tips pls,
      Reproducer code:


      #include <String.au3> #include <Array.au3> #include <IE.au3> $file = @TempDir&'\au3test.tmp' ConsoleWrite('File = '&$file&@CRLF) $oIE = _IECreate('http://autoitscript.com/forum',0,0) _IELoadWait($oIE) $sHTML = _IEBodyReadHTML($oIE) $wFile = FileWrite($file,$sHTML) $nFileHTML = FileOpen($file, 0) If @error then ConsoleWrite('error with FileOpen($file, 0)'&@CRLF) While 1 Local $aArray[10], $aRead = FileReadLine($nFileHTML) If @error then ExitLoop $aSearch = StringInStr($aRead,'<LI><SPAN') If $aSearch > 0 Then $aArray = _StringBetween($aRead, 'href="', '"') _ArrayDisplay($aArray) EndIf WEnd ProcessClose('IEXPLORE.EXE') FileDelete($file)
      Thanks in advance for any tips.

      Tedy.
    • johnmcloud
      By johnmcloud
      Hi guys, i have a simple question. Sometime i'm using _StringBetween for situation like this:

      $test = "asdtewe[asdsad231321132@#]" $string = _StringBetween($test,"[","]") ConsoleWrite($string)
      Result is:

      asdsad231321132@#
      But if i want to remove that piece of string? Example remove all character/number/symbol between "[" and "]", included the "[" "]"? For a result like this:

      asdtewe
      Someone can post an example?
      Thanks for support