mckie@amelia.nas.nasa.gov (William McKie) (07/30/90)
We've got a problem with using calls to the SunFORTRAN 1.2 system( ) library routine (man 3f system) in a program which is redirecting its stdin from a disk file. It appears that the shell which is being forked to execute the command in the character string argument to system( ) is inheriting the fortran program's stdin, & is consuming some of the program's standard input, which leads to trouble on later reads from the stdin. The following simplified program & its run-time output demonstrates the problem. The 'date" command shown below is just for demo purposes. In practice, we need to call the system( ) routine with a variety of command strings. Is there an alternative to using the fortran system( ) library routine for executing an arbitrary command line, or a way to force the forked shell to not use the fortran program's stdin? We would rather not have to link in C code routines to accomplish this. [I noticed that the SunFORTRAN library supports the fork( ) call, but no exec( ) call.] We're running SunOS 4.0.3 on a sparcstation. Thanks for any suggestions, -Bill McKie mckie@sky.arc.nasa.gov cat syscall.f program main character*(50) line integer system do 5100 k=1,2 istatus = system('date') read(5,'(a)') line write(6,'(i2,1x,i3,1x,a)') k,istatus,line 5100 continue stop end f77 syscall.f syscall.f: MAIN main: cat in.data This is the 1st line of input from stdin. This is the 2nd line of input from stdin. a.out <in.data Sun Jul 29 18:59:25 PDT 1990 1 0 This is the 1st line of input from stdin. Sun Jul 29 18:59:25 PDT 1990 dofio: [-1] end of file logical unit 5, named 'stdin' lately: reading sequential formatted external IO part of last data: rom stdin.^J^?| Abort (core dumped)