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 alternative

Old posts that have not been replied to for several years.
Locked
P
Pitchat
Op
Posts: 122
Joined: Tue Feb 18, 2003 11:24 pm
Location: Hebertville Quebec Canada
Contact:

exec alternative

Post by Pitchat »

Hi again !

i use a little scripts that is some sort of "skool.tcl" scripts but it was made for linux eggdrop and i have an error wich is cause by the " exec" commands , i isolate the proc responsible and i`d like to know how can i do the same thing without using the exec command ( you must have guessed , i`m on windows ! )


heres the error

[22:10] (Espion): [22:10] Tcl error [dcc:cours]: couldn't execute "ls": no such file or directory

thanks

Pitchat

Code: Select all

set cours(path) "scripts/cours"
set cours(chan) "#pitchat"

bind dcc o cours dcc:cours
proc dcc:cours {hand idx arg} {
  if {[info proc cours:[lindex $arg 0] ] == ""} {
    putdcc $idx "###Syntaxe: .cours <go|stop|list> <arg>"
    return 0
    } {
    cours:[lindex $arg 0] $hand $idx $arg
  }
}

proc cours:go {hand idx arg} {
  global line cours botnick
  if {![file exists "$cours(path)/[lindex $arg 1].cours"]} {
    cours:list $hand $idx $arg
    return 0
  }
  set coursfile [open "$cours(path)/[lindex $arg 1].cours" r]
  set cours(totline) 0
  while {![eof $coursfile]} {
    set cours(totline) [expr $cours(totline) +1]
    set line($cours(totline)) [gets $coursfile]
  }
  putdcc $idx "Loaded ($cours(totline) lines)"
  setuser $botnick xtra COUR "actif"
  set cours(nb) "1"
  cours:disp
  close $coursfile
}

proc cours:disp {} {
  global timer line cours 
  if {$cours(nb) < $cours(totline)} {
    putserv "PRIVMSG $cours(chan) :$line($cours(nb))"
    set cours(nb) [expr $cours(nb)+1]
    set tmp "cours:disp"
    set timer [utimer 30 $tmp]
    } {
    putserv "PRIVMSG $cours(chan) :End"
  }
}

proc cours:stop {hand idx arg} {
  global timer cours
  if {[info exists timer]} {
    killutimer $timer 
    putdcc $idx "Oki"
    putserv "NOTICE $cours(chan) :CLASS STOPPED BY $hand"
  }
}

proc cours:list {hand idx arg} {
  global cours
  putdcc $idx "Cours files"
  foreach liste [exec ls $cours(path)] {
    if {[string match "*.cours" $liste]} {
      putdcc $idx "[lindex [split $liste .] 0]"
    }
  }
  putdcc $idx "end"
}
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

use glob instead of 'exec ls'
Have you ever read "The Manual"?
P
Pitchat
Op
Posts: 122
Joined: Tue Feb 18, 2003 11:24 pm
Location: Hebertville Quebec Canada
Contact:

Post by Pitchat »

i have replace the exec ls thing with glob but instead of en error a have this

Code: Select all

[04:12] (Pitchat): .cours list
[04:12] (Espion): Cours files
[04:12] (Espion): end
and it doesnt lisdt the files in the directory ( /scripts/cours )

i read the glob page but i do not figure how to apply this in my script since i am quite new at tcl

Code: Select all

proc cours:list {hand idx arg} {
  global cours
  putdcc $idx "Cours files"
  foreach liste [glob $cours(path)] {
    if {[string match "*.cours" $liste]} {
      putdcc $idx "[lindex [split $liste .] 0]"
    }
  }
  putdcc $idx "end"
}
thanks
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

Code: Select all

proc cours:list {hand idx arg} {
  global cours
  putdcc $idx "Cours files"
  foreach liste [glob -nocomplain -dir $cours(path) *.cours] {
    putdcc $idx [file tail [file rootname $liste]]
  }
  putdcc $idx "end"
}
If -dir doesn't work, use [file join $cours(path) *.cours] instead
Have you ever read "The Manual"?
P
Pitchat
Op
Posts: 122
Joined: Tue Feb 18, 2003 11:24 pm
Location: Hebertville Quebec Canada
Contact:

Post by Pitchat »

still doesnt work in this form

Code: Select all

set cours(path) "scripts/cours/"
set cours(chan) "#pitchat"

bind dcc o cours dcc:cours
proc dcc:cours {hand idx arg} {
  if {[info proc cours:[lindex $arg 0] ] == ""} {
    putdcc $idx "###Syntaxe: .cours <go|stop|list> <arg>"
    return 0
    } {
    cours:[lindex $arg 0] $hand $idx $arg
  }
}

proc cours:go {hand idx arg} {
  global line cours botnick
  if {![file exists "$cours(path)/[lindex $arg 1].cours"]} {
    cours:list $hand $idx $arg
    return 0
  }
  set coursfile [open "$cours(path)/[lindex $arg 1].cours" r]
  set cours(totline) 0
  while {![eof $coursfile]} {
    set cours(totline) [expr $cours(totline) +1]
    set line($cours(totline)) [gets $coursfile]
  }
  putdcc $idx "Loaded ($cours(totline) lines)"
  setuser $botnick xtra COUR "actif"
  set cours(nb) "1"
  cours:disp
  close $coursfile
}

proc cours:disp {} {
  global timer line cours 
  if {$cours(nb) < $cours(totline)} {
    putserv "PRIVMSG $cours(chan) :$line($cours(nb))"
    set cours(nb) [expr $cours(nb)+1]
    set tmp "cours:disp"
    set timer [utimer 30 $tmp]
    } {
    putserv "PRIVMSG $cours(chan) :End"
  }
}

proc cours:stop {hand idx arg} {
  global timer cours
  if {[info exists timer]} {
    killutimer $timer 
    putdcc $idx "Oki"
    putserv "NOTICE $cours(chan) :CLASS STOPPED BY $hand"
  }
}

proc cours:list {hand idx arg} { 
global cours 
putdcc $idx "Cours files" 
foreach liste [glob -nocomplain -dir $cours(path) *.cours]

 { 
putdcc $idx  [file join $cours(path) *.cours]
} 
putdcc $idx "end" 
}

i really dont know where to look now

thanks for your efforts
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

Pitchat wrote:

Code: Select all

proc cours:list {hand idx arg} { 
global cours 
putdcc $idx "Cours files" 
foreach liste [glob -nocomplain -dir $cours(path) *.cours]

 { 
putdcc $idx  [file join $cours(path) *.cours]
} 
putdcc $idx "end" 
}
...if that's what your code looks like, no wonder (the extra line breaks before the body of the foreach :P) This is what I meant:

Code: Select all

proc cours:list {hand idx arg} { 
  global cours
  putdcc $idx "Cours files"
  foreach liste [glob -nocomplain [file join $cours(path) *.cours]] {
    putdcc $idx "[file tail [file rootname $liste]]"
  }
  putdcc $idx "end"
}
If it still doesn't work, check your path and working directory. Giving an absolute path would be best, as the working directory won't matter then.
Have you ever read "The Manual"?
P
Pitchat
Op
Posts: 122
Joined: Tue Feb 18, 2003 11:24 pm
Location: Hebertville Quebec Canada
Contact:

Post by Pitchat »

heres the result with your code

[13:29] (Pitchat): .cours list
[13:29] (Espion): Cours files
[13:29] (Espion): end

the directory his /scripts/cours and there is 3 files already in there
Locked