[Arjen Markus] This page is meant to elaborate the management of interactive For tran programs via Tcl. ''Note:'' Very sketchy right now - I want to get the information available ---- Below is a simple example: * Tcl asks for a string and puts it to an executable program written in Fortran. * This program reads the string and writes it out, until the string is "q", then it exits. * At this moment, Tcl must exit too. The trick is to use file events to handle the buffering and broken pipe issues correctly and to use the non-standard Fortran routine flush() to flush the output buffers. ---- The Tcl code: global inout set inout [open "|copy_inp" "w+"] fconfigure $inout -buffering none puts "Input:" fileevent $inout readable { gets $::inout copied puts $copied if { [eof $inout] } { close $inout; set forever 1 } } fileevent stdin readable { gets stdin line puts $::inout $line puts "Input:" } vwait forever ---- The Fortran code: ! copy_inp.f90 -- ! Copy stdin to stdout - IPC test ! program copy_inp ! Compaq Visual Fortran requires: ! use dflib character(len=60) :: string do read(*,*) string write(*,*) 'Copied: ', string call flush( 6 ) ! On SGI use: ! call flush( 101 ) if ( string .eq. 'q' ) stop enddo end program ''Notes:'' * Standard output is usually unit 6, but on SGI it is unit 101 * As FLUSH() is non-standard, you may need to add a USE statement, or link with a special library ---- See also: [open], [exec], [Inventory of IPC methods]