Silverfrost Forums

Welcome to our forums

Managing piped input

30 Mar 2018 1:19 #21697

I would like to follow up on my problem of providing input to a program when running in a batch file. I have two issues I would like know if others have overcome.

First, for command input, you need to provide a seperate file for the text input. The Apollo O/S provided a syntax that the commands could be taken from the same batch file. Has anyone found this capabiliy?

Second, when using input from a text file via: Program < commands.txt When the commands.txt file is exhausted (end of file on read), how can you recover and continue to provide interactive input ?

Any suggestions ?

30 Mar 2018 1:00 #21699

As we know, the Windows command processor is not as capable as Unix shells such as Bash. You can obtain and use a version of Bash for Windows.

Here is something that you can do as a stop-gap: you can read a known data file by passing the name of the file as an argument, and check for EOF as you read and process the data from the file. When EOF occurs, you switch to reading data from standard input. Terminate by typing in Ctrl+Z.

program testhere
implicit none
character(80) :: line
character(10) :: fname
integer :: i = 0
!
! retrieve file to read first
!
call get_command_argument(1,fname)
!
! read and process input from file
!
open(10,file=fname,status='old')
do
   read(10,'(A)',end=10)line
   i = i+1
   print 30,i,line
end do
10 close(10)
!
! file has been read, continue to read from standard input
!
do
   read(*,'(A)',end=20)line
   i = i+1
   print 30,i,line
end do
20 stop
30 format(i2,1x,A)
end program
Please login to reply.