![]() |
Available news archives:
comp.lang.tcl
-
comp.lang.python
-
comp.security.firewalls
-
sci.crypt -
comp.lang.php -
comp.lang.javascript
|
|
comp.lang.tcl archivecommand pipelines, blocking and stderr
From: David N. Welton <davidw@dedasys.com>
Date: Fri Sep 30 2005 - 11:03:03 CEST
Hello,
I've written a bit of code that is quite useful for launching commands
if { [eof $fl] } {
which is saying that if there is nothing more to read from the
Opinions?
Thanks,
-- David N. Welton - http://www.dedasys.com/davidw/ Linux, Open Source Consulting - http://www.dedasys.com/ ------------------ namespace eval runcommand {} proc ::runcommand::runcommand {cmd} { variable standarderror variable standardout #puts "running $cmd" set standardout "" set standarderror "" set fl [open "| $cmd" r] fconfigure $fl -blocking 0 fconfigure $fl -buffering none ::runcommand::runcommandloop $fl vwait ::runcommand::finished #puts "stdout: $standardout" #puts "stderr: $standarderror" return "Output:\n$standardout\nErrors:\n$standarderror" } proc ::runcommand::runcommandloop {fl} { variable standarderror variable standardout append standardout [read $fl] if { [eof $fl] } { fconfigure $fl -blocking 1 catch { close $fl } err append standarderror $err after 1 [list set ::runcommand::finished 1] return } after 100 [list ::runcommand::runcommandloop $fl] } set out [runcommand::runcommand "make aaaa"] puts $outReceived on Sat Oct 15 03:53:48 2005 |