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.

launching a proc in background?

Help for those learning Tcl or writing their own scripts.
Post Reply
n
needHelp
Voice
Posts: 2
Joined: Sat Nov 03, 2007 8:27 pm

launching a proc in background?

Post by needHelp »

hi, i wrote a proc for my eggdrop which takes some time.
while running this proc the eggdrop cant respond to other commands and sometimes i get ping timeout.

the proc has to take the long time so i dont want to change anything on it.

instead im looking for a method to call the proc from the binded proc to launch in background or in a child process.

i already tried forking but without success.

any1 here has an idea?

thx in advance.
User avatar
TCL_no_TK
Owner
Posts: 509
Joined: Fri Aug 25, 2006 7:05 pm
Location: England, Yorkshire

Post by TCL_no_TK »

I dont know if thats really possible, thou it all depends on what the script dose? If its something like running a progeram or an exacutable, that would probably ...i would think could easyerly be done. But other than that, i could recommend execting tclsh and running it that way? or use of a pipe or unix sock maybe?
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Could usually be done quite easily..

Depending on system, this might work:

Code: Select all

exec -- command &
A slightly more complicated approach, that also allows you to access the stdin and stdout pipes through file-handles

Code: Select all

proc readcmd {process} {
 if {[gets $process data] < 0} {
  if {[eof $process]} {
   close $chan
   return
  }
 } {
  #Process the output stored in $data, or just ignore it?
 }
}

set pid [open "| command" "RDWR"]
fconfigure $pid -blocking 0 
fileevent $pid -readable [list readcmd $pid]
NML_375
n
needHelp
Voice
Posts: 2
Joined: Sat Nov 03, 2007 8:27 pm

Post by needHelp »

as i already said i dont want to run an executable.

But i think i solved it on my own using Thread 2.6 package.
User avatar
CrazyCat
Revered One
Posts: 1334
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

Another (silly?) solution could be the use of a timer (1 seconde) to launch your proc.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Registering a timer would still cause it to be executed within the same thread, causing the same blocking condition.
I have no experience using the Thread package with eggies myself, would be nice to hear if it goes all well.
NML_375
Post Reply