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.

Non I/O Blocking exec replacement ?

Old posts that have not been replied to for several years.
Locked
User avatar
GodOfSuicide
Master
Posts: 463
Joined: Mon Jun 17, 2002 8:00 pm
Location: Austria

Non I/O Blocking exec replacement ?

Post by GodOfSuicide »

Is there some module out there that replaces the exec cmd with a non blocking one ? (no, i dont mean bgexec or open) ?

like for example
set outfile [myexec "ping $host" ping_get]
and each time this exec sends a new line -> it gets sent to ping_get

maybe one of the coders in here can realize this idea..my own C / C++ skills are too low for this
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

why not open |?
User avatar
GodOfSuicide
Master
Posts: 463
Joined: Mon Jun 17, 2002 8:00 pm
Location: Austria

Post by GodOfSuicide »

user wrote:why not open |?
is it possible to use open the way i just told ? (seriouse question, i really dont know)
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

GodOfSuicide wrote:is it possible to use open the way i just told ?
Yes. By using 'fconfigure' to make it non-blocking and 'fileevent readable' to set up the callback. The only thing that is a bit tricky is redirection of stderr...i'll get back to you on this...try this code:

Code: Select all

proc myexec {cmd callback} {
	set f [open |$cmd r+]
	fconfigure $f -blocking 0
	fileevent $f readable [list myexecIn $f $callback]
	set f
}
proc myexecIn {f callback} {
	if {[set i [gets $f line]]>0} {
		uplevel #0 [concat $callback [list $line]]
	} elseif {$i==-1} {
		close $f
		uplevel #0 [concat $callback {{}}]
	}
}
The callback command will be called for each line of output. Blank lines are ignored and when the process ends the callback command is called with a blank argument - like a dcc connection put under control under eggdrop. (the callback can be a list of command+arguments just like the built in callbacks.) This code is by no means final, but it's something to start with :)
Locked