| View previous topic :: View next topic |
| Author |
Message |
downloaded Voice
Joined: 30 Jul 2014 Posts: 3
|
Posted: Wed Jul 30, 2014 4:45 am Post subject: Exec help |
|
|
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 |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Wed Jul 30, 2014 5:08 am Post subject: |
|
|
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 |
|
 |
downloaded Voice
Joined: 30 Jul 2014 Posts: 3
|
Posted: Wed Jul 30, 2014 3:00 pm Post subject: |
|
|
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 |
|
 |
downloaded Voice
Joined: 30 Jul 2014 Posts: 3
|
Posted: Sat Aug 02, 2014 6:44 pm Post subject: |
|
|
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 |
|
 |
|