Posted to tcl by schelte at Sat Oct 05 13:44:24 GMT 2024view raw

  1. proc corobgexec {args} {
  2. set fd [open "|$args &"]
  3. fconfigure $fd -blocking 0
  4. fileevent $fd readable [list [info coroutine] data]
  5. set output {}
  6. while {![eof $fd]} {
  7. yield
  8. # Collect any output
  9. append output [read $fd]
  10. }
  11. fconfigure $fd -blocking 1
  12. try {
  13. close $fd
  14. } on ok {output} {
  15. puts "$cmd: Command successful"
  16. } trap {CHILDSTATUS} {output options} {
  17. set result [lindex [dict get $options -errorcode] end]
  18. if {$result == 3} {
  19. puts "$cmd: Argument undefined"
  20. } elseif {$result == 4} {
  21. puts "$cmd: Login Failed"
  22. } elseif {$result == 1} {
  23. puts "$cmd: Process Cancelled by user"
  24. }
  25. }
  26. return $output
  27. }
  28.  
  29. proc steps {} {
  30. set result [corobgexec step1.sh]
  31. # update GUI
  32. set result [corobgexec step2.sh]
  33. # update GUI
  34. set result [corobgexec step3.sh]
  35. # update GUI
  36. set result [corobgexec step4.sh]
  37. # update GUI
  38. set result [corobgexec step5.sh]
  39. # update GUI
  40. }
  41.  
  42. button .b1 -text Run -command [list coroutine bgsteps steps]
  43.  

Comments

Posted by schelte at Sat Oct 05 13:46:54 GMT 2024 [text] [code]

$cmd should be $args.