Jump to content



Photo

while loop times out?


  • Please log in to reply
7 replies to this topic

#1 huskies

huskies

    Wayfarer

  • Active Members
  • Pip
  • 64 posts

Posted 02 November 2011 - 09:45 PM

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
Posted Image<It Shall Be Done>







#2 Jos

Jos

    oh joy ...

  • Developers
  • 21,064 posts

Posted 02 November 2011 - 09:49 PM

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

Edited by Jos, 02 November 2011 - 09:49 PM.

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


#3 Melba23

Melba23

    Yes, me!

  • Moderators
  • 15,387 posts

Posted 02 November 2011 - 09:54 PM

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
StringSize - Automatically size controls to fit text - ExtMsgBox - A user customisable replacement for MsgBox

Toast - Small GUIs which pop out of the Systray - Marquee - Scrolling tickertape GUIs

Scrollbars - Automatically sized scrollbars with a single command - GUIFrame - Subdivide GUIs into many adjustable frames

GUIExtender - Extend and retract multiple sections within a GUI - NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes

ChooseFileFolder - Single and multiple selections from specified path tree structure - - Notify - Small notifications on the edge of the display

RecFileListToArray - An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options

GUIListViewEx - Insert, delete, move, drag and sort ListView items


#4 Xandy

Xandy

    Relationships, Battleships, Aircraft Carryers

  • Active Members
  • PipPipPipPipPipPip
  • 939 posts

Posted 02 November 2011 - 10:01 PM

$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, 02 November 2011 - 10:02 PM.


#5 Melba23

Melba23

    Yes, me!

  • Moderators
  • 15,387 posts

Posted 02 November 2011 - 10:05 PM

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
StringSize - Automatically size controls to fit text - ExtMsgBox - A user customisable replacement for MsgBox

Toast - Small GUIs which pop out of the Systray - Marquee - Scrolling tickertape GUIs

Scrollbars - Automatically sized scrollbars with a single command - GUIFrame - Subdivide GUIs into many adjustable frames

GUIExtender - Extend and retract multiple sections within a GUI - NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes

ChooseFileFolder - Single and multiple selections from specified path tree structure - - Notify - Small notifications on the edge of the display

RecFileListToArray - An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options

GUIListViewEx - Insert, delete, move, drag and sort ListView items


#6 Xandy

Xandy

    Relationships, Battleships, Aircraft Carryers

  • Active Members
  • PipPipPipPipPipPip
  • 939 posts

Posted 02 November 2011 - 10:07 PM

I did not know that, thanks M23.

#7 huskies

huskies

    Wayfarer

  • Active Members
  • Pip
  • 64 posts

Posted 02 November 2011 - 10:21 PM

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
Posted Image<It Shall Be Done>

#8 czardas

czardas

  • Active Members
  • PipPipPipPipPipPip
  • 5,075 posts

Posted 02 November 2011 - 10:27 PM

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, 02 November 2011 - 10:32 PM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users