Prev: itcluno state
Next: subclassing a widget?
From: Jan Kandziora on 12 Jan 2010 09:42 Hello, I need to pass binary (image) data to an external pipeline, and read it back. Seems this is not possible with "exec". I've already read http://www.tcl.tk/cgi-bin/tct/tip/259.html, is there no implementation of this TIP so far? Is there any other "simple" solution without the use of temporary files? Kind regards Jan
From: Alexandre Ferrieux on 12 Jan 2010 10:00 On Jan 12, 3:42 pm, Jan Kandziora <j...(a)gmx.de> wrote: > Hello, > > I need to pass binary (image) data to an external pipeline, and read it > back. Seems this is not possible with "exec". I've already readhttp://www..tcl.tk/cgi-bin/tct/tip/259.html, is there no implementation of > this TIP so far? Uhhh, I admit it fell below the radar somehow :/ > Is there any other "simple" solution without the use of temporary files? Yes; spawn the process between pipes, and use both nonblocking writes and reads, and the event loop, to feed it with data and get back the results. Of course if you do this in a blocking fashion you may deadlock if the exchanged data size exceeds a pipe buffer (4K). You'll also need the recent half-close to signal end of input, but the half-close must be done when we're sure not to block, because the closing itself switches back to blocking mode: set ff [open |cmd r+] fconfigure $ff -translation binary -blocking 0 puts -nonewline $ff data fileevent $ff readable { set data [read $ff] if {[string length $data]==0} {set ::finished 1} else {swallow $data} } fileevent $ff writable {set ::done 1} vwait ::done close $ff w vwait ::finished I admit this is disgusting ! -Alex
From: Andreas Leitgeb on 12 Jan 2010 10:06 Jan Kandziora <jjj(a)gmx.de> wrote: > I need to pass binary (image) data to an external pipeline, and read it > back. Seems this is not possible with "exec". I've already read > http://www.tcl.tk/cgi-bin/tct/tip/259.html, is there no implementation of > this TIP so far? > Is there any other "simple" solution without the use of temporary files? For [exec <<] there is currently no way. I reported that bug already in 2005, and it generated a few comments, speculating about some internal API function that might have been used by some extension. Then in 2006 that API-problem was identified as being no issue, but then it seemingly was forgotten. It is BugId: 1189293 <https://sourceforge.net/tracker/index.php?func=detail&aid=1189293&group_id=10894&atid=110894> You could, however, use open with a pipe. Then you can fconfigure the returned channel for binary, or just specify "wb" as the access mode, and then you write the image data to the channel. There are of course other caveats involved with that, like eventually handling output of the external process and a risk of lock-ups (both to be solved with event-handlers and "fileevent")
From: Jan Kandziora on 12 Jan 2010 11:23 Alexandre Ferrieux schrieb: > > I admit this is disgusting ! > vwait makes my mind boggle. But thanks, I will try it. Kind regards Jan
|
Pages: 1 Prev: itcluno state Next: subclassing a widget? |