This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Exec help

Help for those learning Tcl or writing their own scripts.
Post Reply
d
downloaded
Voice
Posts: 3
Joined: Wed Jul 30, 2014 4:24 am

Exec help

Post by downloaded »

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?
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

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.
d
downloaded
Voice
Posts: 3
Joined: Wed Jul 30, 2014 4:24 am

Post by downloaded »

Tks for your help caesar.

Following you hint i came this far:

Code: Select all

	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.
d
downloaded
Voice
Posts: 3
Joined: Wed Jul 30, 2014 4:24 am

Post by downloaded »

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: Select all

bgexec "lftp -f script.txt" callback
To catch the response from lftp use:

Code: Select all

proc callback {input} {
foreach line [split $input "\n"] {
putlog "$line"
}
}
Post Reply