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:
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:
See also: open, exec, Inventory of IPC methods