I run fortran77 program in terminal


and the program ask for input and output file. What should I write to terminal when I have the names of input and output files in a file - in two columns? I would like to run the program for all rows in the file with names.

Or - how to run a program with input information like parameters?

Or how to write the name of file direct in script? Instead of

READ(+,'(A)') OUT
  • How to write it in code please? Instead of READ(+,'(A)') IN and READ(+,'(A)') OUT
    – Arrara
    Oct 13, 2019 at 15:10

2 Answers 2


I made the following program file prog.f

       program test

       character IN*30,OUT*30,line*80

       PRINT *,'Input file '
       READ(*,'(A)') IN
       PRINT *,'Output file?'
       READ(*,'(A)') OUT

       read (1,'(a80)') line
       write (2,*) "I read ", line

compiled & linked it with

gfortran prog.f -o prog

I put a text string into an input file

echo "Hello World" > in

Then I sent the names of the input file in and output file out to the program

$ <<< 'in
out' ./prog
 Input file 
 Output file?

and checked the output file

$ cat out
 I read Hello World                                                                     

<<< works in bash. You may prefer piping from echo which is more portable,

$ rm out
rm: remove normal file 'out'? y

$ echo 'in
out' | ./prog
 Input file 
 Output file?
$ cat out
 I read Hello World                                                                     
  • 1
    Interesting! And this outta space file arguments...has to be so in fortran? "cpio" is similar, but at least the output you can give seperately. And here: "<inoutfiles ./prog" does not work? With "inoutfiles" containing the lines "in" and "out", "in" containing the data and "out" being a path. My brain hurts.
    – user373503
    Oct 13, 2019 at 17:06
  • 1
    @rastafile, It is possible to make fortran read from standard input and write to standard output, at least with some modern versions. In this case redirection is possible as you suggest.
    – sudodus
    Oct 13, 2019 at 17:09
  • 1
    Thank you very much
    – Arrara
    Oct 13, 2019 at 17:16
  • 1
    I have a slight dejavu -- I think I read something about that special fortran style long time ago. Now it "hit" me. Nice!
    – user373503
    Oct 13, 2019 at 17:18
  • 2
    @Arrara, You are welcome :-)
    – sudodus
    Oct 13, 2019 at 17:22

If you are lucky then maybe

<infile ./program  >outfile

will work. Redirection to give a filedescriptor. Options/arguments???

While we earthlings write something like...

$ <77in cat >77.out
$ cat 77in >77.out

(This copies just 77in to 77.out)

...this Fortran77 program/command wanted it's operands linewise in one input file/stream:

$  <77.io cat

Now if cat was something else it would parse first line as input file (containing "hello\nworld" eg.) and the second as file to create.

And that is just the newer, easy way it seems...

Instead of a long argument list like cp -a dir1 dir2 dest it is <in_list cpa77.

But then you need an additional file...just like modern cpio does:

<filelist cpio -o >files.cpio. Of course cpio just needs STDIN linewise:

find . | cpio -o >files.cpio

(cpio has this special call syntax because of its functioning, working with many files. It is one command and a half. Same for tar, in a different way)

If anything is typical of unix, then it is this flexibility in feeding control and data to commands in the shell. As I commented: good Q after all! (Thx to accepted answer!)

  • Should I replace -o1 -o2?
    – Arrara
    Oct 13, 2019 at 15:27
  • @Arrara Yes, I just saw you wrote "parameters". Now these things overlap. A call with argument "-V" as option for "print version" for example.
    – user373503
    Oct 13, 2019 at 15:35
  • I am sorry, I ment output and input as parameters. When I write <infile ./program >outfile it does not work
    – Arrara
    Oct 13, 2019 at 15:37
  • ...because the correct options are missing.
    – user373503
    Oct 13, 2019 at 15:40
  • What are options please?
    – Arrara
    Oct 13, 2019 at 15:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .