bashfortraninteractive

Passing arguments to interactive fortran program


I have a fortran program (which I cannot modify) that requires several inputs from the user (in the command line) when it is run. The program takes quite a while to run, and I would like to retain use of the terminal by running it in the background; however, this is not possible due to its interactive nature.

Is there a way, using a bash script or some other method, that I can pass arguments to the program without directly interacting with it via the command line?

I'm not sure if this is possible; I tried searching for it but came up empty, though I'm not exactly sure what to search for.

Thank you!

ps. I am working on a unix system where I cannot install things not already present.


Solution

  • You can pipe it in:

    $ cat delme.f90
    program delme
        read(*, *) i, j, k
        write(*, *) i, j, k
    end program delme
    
    $ echo "1 2 3" | ./delme
               1           2           3
    
    $ echo "45 46 47" > delme.input
    $ ./delme < delme.input
              45          46          47
    
    $ ./delme << EOF
    > 3 2 1
    > EOF
               3           2           1