Jump to content

while loop times out?


huskies
 Share

Recommended Posts

Sometimes if this while loop have to run for more than 2 minutes,the programs gets stuck. As in my next step never gets ran. but for regular situation (around 10 seconds, it runs perfectly), so do while loops in Autoit time out after a while?

$file = fileopen($PuttyLogpath,0)

Local $str = FileReadLine($file, -1)

while $str <> $Message

sleep(200)

$str = FileReadLine($file, -1)

WEnd

<It Shall Be Done>
Link to comment
Share on other sites

  • Developers

You need to test the success of filereadline and act on it in case of EOF.

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Moderators

huskies,

do while loops in Autoit time out after a while?

No. :oops:

By the way, I am none too sure that you will ever get out of your loop as you might be locking the file when you open it and so it can never be re-read. :rip:

I found that this worked better: :)

$Message = "End"

$file = "test.txt"

Local $str = FileReadLine($file, -1)

While $str <> $Message
    Sleep(200)
    $str = FileReadLine($file, -1)
    ConsoleWrite($str & @CRLF)
WEnd

Any help? :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
Share on other sites

$file = fileopen($PuttyLogpath, 0)
Local $str = FileReadLine($file, -1)
while $str <> $Message
    sleep(200)
    $str = FileReadLine($file, -1)
    if @error<> 0 then ExitLoop; tests for EOF
WEnd
ConsoleWrite(@CRLF&"program exited loop")

Edited by songersoft
Link to comment
Share on other sites

  • Moderators

Guys,

Why does he need to test for EOF? With the "line" parameter set to -1, the code is always reading the last line so there will never be an EOF return. :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
Share on other sites

thanks guys, im actually on the train right now so i will give it a shot when i get home. just a little context, what I am trying to do is run a query in a database with unix, and it will take between 5 seconds to 2 minutes, when the next command line is ready that means the query is done, then I will enter my next command

here are some of my custom functions, I have Putty output the results in a txt file on my desktop so I can interact with it

StartPutty($Puttypath, "db5")

ReadLog($PuttyLogpath, "[company@db5.prod ~]$ ")

sending("./generate_mtu_data.sh apps") //this is the query that will take 2 minutes to run

ReadLog($PuttyLogpath, "[company@db5.prod ~]$ ")

blah

blah

<It Shall Be Done>
Link to comment
Share on other sites

I presume the file will be written to at some point, otherwise the last line may never equal $Message, and you will still be stuck in an infinite loop. You may want to add a time out option anyway to prevent that from happening.

Edited by czardas
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...