forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Managing piped input

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General
View previous topic :: View next topic  
Author Message
JohnCampbell



Joined: 16 Feb 2006
Posts: 1983
Location: Sydney

PostPosted: Fri Mar 30, 2018 2:19 am    Post subject: Managing piped input Reply with quote

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 ?
Back to top
View user's profile Send private message
mecej4



Joined: 31 Oct 2006
Posts: 978

PostPosted: Fri Mar 30, 2018 2:00 pm    Post subject: Reply with quote

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.
Code:
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
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group