From: ian AT cygnus DOT com Subject: Re: Pipe with TCL/TK 7 Apr 1998 09:43:12 -0700 Message-ID: <199804062057.QAA22686.cygnus.gnu-win32@tweedledumb.cygnus.com> References: <199804060717 DOT JAA16572 AT hermes7 DOT cst DOT cnes DOT fr> To: genesis AT hermes9 DOT cst DOT cnes DOT fr Cc: gnu-win32 AT cygnus DOT com In gnu-win32 genesis AT hermes9 DOT cst DOT cnes DOT fr (Utilisateur genesis) writes: >I use TCK/TK with GNUWIN32-B19. My application use Tcl functions libraries to send Tcl and Tk commands. >I use pipe to interprocess communication, and I want to detect when a pipe may be read. >For that I created pipe with "pipe" function, and started a function handler "action_pipe" (for execute a callback when pipe may be read). > int fid[2]; > Tcl_Channel pipe_channel; >#ifdef _WIN32 > HANDLE pipe_handle; >#else > int pipe_fd; >#endif > pipe (fid); >#ifdef _WIN32 > pipe_fd = get_osfhandle(fid[0]); >#else > pipe_fd = fid[0]; >#endif > pipe_channel = Tcl_MakeFileChannel ( pipe_fd TCL_READABLE ); > Tcl_CreateChannelHandler ( pipe_channel, TCL_READABLE, > action_pipe, (ClientData) fid[0] ); >I've the same source code for SUN Solaris 2.5 and Windows NT GNUWIN32-B19. I've TCL/TK 8.0 on both platforms. I use -D_WIN32 compilation option on Windows. >I've no problem on SUN platform, the handler "action_pipe" is activate when a pipe may be read. >On Windows platform my application block when the TCl/TK event loop is started. Windows pipes are really lame. There is no way to get them to send you a message when there is some data to read, so you have to set up a separate thread to sit around trying to read from them. That's the point behind all the code I added to tclWinPipe.c. The problem with what you are trying to do is that you are treating a pipe as a file, by calling Tcl_MakeFileChannel. That won't work. On Windows, pipes are not files. The code I added to tclWinPipe.c will only help if you create a Tcl pipe. What you should do is look at the expect program, at expect/exp_event.c, where I had to get a similar thing to work. Look particularly at make_pipe_channel and friends. That will show you how to make a pipe channel that will work on Windows. It's pretty hairy. Ian - For help on using this list (especially unsubscribing), send a message to "gnu-win32-request AT cygnus DOT com" with one line of text: "help".