egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Exec help

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
downloaded
Voice


Joined: 30 Jul 2014
Posts: 3

PostPosted: Wed Jul 30, 2014 4:45 am    Post subject: Exec help Reply with quote

I've been coding a script to transfer some files using lftp. Lftp is launched with exec. From what i searched in this forum seems i have two options:

1- Run exec and wait for transfer to finish and get a sucess return code or failed. In the meanwhile the eggdrop stops responding and if the transfer takes long enough it will timeout from IRC.

2- Run exec in the backgroud and forget about any sucess confirmation or error handling.

Is there a 3rd option?
Back to top
View user's profile Send private message
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Wed Jul 30, 2014 5:08 am    Post subject: Reply with quote

3rd option my guess would be to use fileevent with a callback to another proc.

Anyway, I haven't done this before but I recall there was a topic regarding the same issue, like this one. Or you could search the forum with fileevent as keyword.
_________________
Once the game is over, the king and the pawn go back in the same box.
Back to top
View user's profile Send private message
downloaded
Voice


Joined: 30 Jul 2014
Posts: 3

PostPosted: Wed Jul 30, 2014 3:00 pm    Post subject: Reply with quote

Tks for your help caesar.

Following you hint i came this far:

Code:
   set lftpexe [open "|lftp -f script.txt"]
   fconfigure $lftpexe -blocking 0
   fileevent $lftpexe readable [list lftpcallback $lftpexe]

proc lftpcallback {lftpexe} {
   putlog "Reader"
   gets $lftpexe spline
   putlog "Read: $spline"
}


Its not working since i get like 10 "Reader" and "Read:" in each second and after a while the lftp process appears as "defunct". From what i understood it means there's something to be read before the precess ends.

I think i may need to close channel inside lftpcallback, but didnt have the time to test it.
Back to top
View user's profile Send private message
downloaded
Voice


Joined: 30 Jul 2014
Posts: 3

PostPosted: Sat Aug 02, 2014 6:44 pm    Post subject: Reply with quote

Took me some time to get there... But i did. For future owners searching for this here it is.

The simplest way is to use bgexec scripts. I used the one caeser posted, but there are others online.

To launch your code use:

Code:
bgexec "lftp -f script.txt" callback


To catch the response from lftp use:

Code:
proc callback {input} {
foreach line [split $input "\n"] {
putlog "$line"
}
}
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber