Sign in to follow this  
Followers 0
huskies

while loop times out?

8 posts in this topic

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>

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

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


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

#4 ·  Posted (edited)

$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

I am not a lawyer.  (-_-) Xandy About  (^o^) Discord - Xandy Programmer

Share this post


Link to post
Share on other sites

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


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

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>

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

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

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