<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">Thanks David DeSimone,<br><br>That explanation helps a lot. The extra flush does straighten out the duplicate messages.<br><br>I certainly have more to learn, but am making progress.<br><br>Phil<br><br><br><br>--- On <b>Tue, 11/2/10, Phil Osipher <i><phlosipher@yahoo.com></i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: Phil Osipher <phlosipher@yahoo.com><br>Subject: Re: [imapfilter-devel] daemon mode<br>To: "Lefteris Chatzimparmpas" <lefcha@hellug.gr><br>Cc: imapfilter-devel@lists.hellug.gr<br>Date: Tuesday, November 2, 2010, 9:10 AM<br><br><div id="yiv2096510158"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="font: inherit;" valign="top">OK,<div><br></div><div>It makes sense that you have closed stdout. But I am still puzzled. I have
converted my script to write to a file, and I attach it to this email. It just replaces the print statements with a write, after opening a log file. But there is still some unexpected behavior.</div><div><br></div><div>Here are the log file contents after the script has run for a minute. The lines surrounding the file "open" are printed multiple times.</div><div>------------------</div><div><div>test</div><div>a</div><div>test</div><div>a</div><div>test</div><div>a</div><div>abcd <-- b</div><div>abcd <-- b</div><div>----------------</div><div><br></div><div>The line "abcd" is being printed every 30 seconds as I have asked, but the "test" and "a" lines are being printed 3 times, and they should only be printed once. It looks as though when the script is
being "demonized" it is "re-executed" two more times prior to a transition to the "forever" function. Can you clarify what is going on?</div><div><br></div><div>Note that in the "real script" (not this test script) I wish to query the user for the password, and then daermonize the forever function to keep it checking the mailbox, so it is important that some of the script is run "interactively". and I need to be able to exclude those code fragments from being executed multiple times. Do you have a suggestion?</div><div><br></div><div>Thanks</div><div><br></div>Phil<br><br></div><div>--- On <b>Tue, 11/2/10, Lefteris Chatzimparmpas <i><lefcha@hellug.gr></i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: Lefteris Chatzimparmpas <lefcha@hellug.gr><br>Subject: Re: [imapfilter-devel] daemon mode<br>To: "Phil Osipher" <phlosipher@yahoo.com><br>Cc:
imapfilter-devel@lists.hellug.gr<br>Date: Tuesday, November 2, 2010, 2:19 AM<br><br><div class="yiv2096510158plainMail">Hello,<br><br>Basically you are right that there is something simple that you missed<br>and confuses you. When in daemon mode imapfilter detaches itself from<br>the controlling terminal (closes stdin/stdout/stderr) and goes in the<br>background. So all the print() you do inside forever will never be<br>printed anywhere.<br><br>For testing you could try opening a file and then writing to that<br>file instead.<br><br>L.<br><br><br>On 11/02/2010 05:52 AM, Phil Osipher wrote:<br>> Please forgive the following very stupid question.<br>> <br>> In learning imapfilte rand lua I have written some reasonably complex imapfilter and lua scripts, and although I am new to them, they seem to work fine when executed "once". <br>> <br>> But I am puzzled over the use of the "daemon mode". <br>> <br>> Here is the issue. My
employer does not
allow me to store password in scripts, or files accessed by scripts. (Encrypted or not). So to filter a mailbox, I have decided to start an imapfilter script interactively in the console, query for a password, and then switch to daemon mode to occasionally access a mailbox folder for days or weeks continuously and do some stuff to it (which I may post later to ask for advice/improvements about at a later date). <br>> <br>> But I am not having any luck with using the tools in daemon mode.<br>> <br>> Here is a simple example of a script, simplified to get to the essence of the problem and make it easy for you to help me <br>> <br>> --------------------------------<br>> function forever()<br>> account1 = IMAP {<br>> server = 'server.domain.com',<br>> username = '<a rel="nofollow">user@domain.com</a>',<br>> password = passwd,<br>>
}<br>> print("b")<br>> end<br>> <br>> passwd = "abcd"<br>> <br>> print("a")<br>> <br>> <br>> --daemon_mode(10,forever)<br>> become_daemon(10,forever)<br>> --forever()<br>> print("c")<br>> --------------------------<br>> <br>> The script behaves predictably if I enable the line that invokes function "forever" explicitly.<br>> e.g. invokng the script with "imapfilter -c test.lua" when I enalbe the line "forever()" produces output<br>> <br>> a<br>> b<br>> c<br>> <br>> <br>> But if I modify the script to use the line with "daemon_mode" or "become_deamon" it prints <br>> "a", then hangs. I expected it to repeat "b" repeatedly every 10 seconds, and never reach the line to print "c".<br>> <br>> What am I doing wrong? It must be something very simple. So sorry to be
missing something basic. I have tried "flushing" stdout (not shown) but that doesn't seem to help. I must be missing something else that is simple.<br>> <br>> Also, what is the difference between "become_daemon" and "daemon_mode"?<br>> <br>> <br>> Thanks for the help<br>> <br>> Phil<br>> <br>> <br>> <br>> <br>> <br>> <br>> <br>> <br>> <br>> <br>> _______________________________________________<br>> Imapfilter-devel mailing list<br>> <a rel="nofollow">Imapfilter-devel@lists.hellug.gr</a><br>> <a rel="nofollow" target="_blank" href="http://lists.hellug.gr/mailman/listinfo/imapfilter-devel">http://lists.hellug.gr/mailman/listinfo/imapfilter-devel</a><br></div></blockquote></div></td></tr></tbody></table><br>
</div><br>-----Inline Attachment Follows-----<br><br><div class="plainMail">_______________________________________________<br>Imapfilter-devel mailing list<br><a ymailto="mailto:Imapfilter-devel@lists.hellug.gr" href="/mc/compose?to=Imapfilter-devel@lists.hellug.gr">Imapfilter-devel@lists.hellug.gr</a><br><a href="http://lists.hellug.gr/mailman/listinfo/imapfilter-devel" target="_blank">http://lists.hellug.gr/mailman/listinfo/imapfilter-devel</a></div></blockquote></td></tr></table><br>