-1

I run a fortran program with bash:

#!/bin/sh
./program

and the program give three questions. How to give answers/arguments into bash script?

I tried:

#!/bin/sh
echo "1 0 3,1.01" | program

but the error is command not found. Thank you

Lukáš Altman
  • 497
  • 1
  • 5
  • 15

1 Answers1

2

You are lacking the path.

echo "1 0 3,1.01" | ./program

Maybe you should have newlines between the answers, though?

printf "1\n0\n3,1.01\n" | ./program

A much better design would be for your Fortran program to accept its input as command-line arguments. Without the program's source, I can't say how to change it; but then you could say

./program 1 0 3,1.01
tripleee
  • 175,061
  • 34
  • 275
  • 318
  • 1
    Thank you very much for your answer. In the first and second command I have a problem with the third argument that consists of more numbers. In the third command the question in terminal althrough appear. – Lukáš Altman May 01 '19 at 13:58
  • 2
    I'm sorry, I don't understand, could you rephrase the problem? – tripleee May 01 '19 at 14:25
  • 2
    Like I wrote in the answer already, the third option requires you to make changes to your Fortran program. – tripleee May 01 '19 at 14:26
  • 1
    There is mistake: `At line 58 of file program.f (unit = 5, file = 'stdin') Fortran runtime error: End of file` . I use a command: `echo "0 0 4281,4503,1.01" | ./program` . `4281,4503,1.01` is exactly what I write to terminal when a program runs. – Lukáš Altman May 01 '19 at 19:33
  • 2
    Did you try with newlines between the numbers instead of spaces? Again, this is very hard to debug without access to at least a tiny part of your Fortran code -- what inputs exactly does it require, in what format? Try to boil this down to a [mcve] and maybe post a new question if it's a lot different from what you already posted here. – tripleee May 02 '19 at 05:02
  • 1
    I tried to write newlines between the numbers instead of spaces, but there was an error. I replace it in code of program. Thank you – Lukáš Altman May 02 '19 at 06:35