Feeding a command using file redirection or pipe doesn't always work
2
votes
2
answers
402
views
I've downloaded this program [construct2d](https://sourceforge.net/projects/construct2d/) and compiled it using GNU Fortran
gfortran 9.3.0
.
You can compile the program using gnu make:
make
(compilation time: 10 seconds on my PC running Ubuntu 20.04 with GNU bash, version 5.0.17(1)-release (x86_64-pc-linux-gnu)
).
This program doesn't work with arguments, instead I have to enter manually the options. In order to avoid that tedious workflow I wrote the options in a file instructions.txt
to feed it.
construct2d < instructions.txt
The content of instructions.txt
is:
naca0012.dat
SOPT
NSRF
80
RADI
5
NWKE
5
QUIT
VOPT
JMAX
5
YPLS
5
RECD
1E5
QUIT
GRID
SMTH
QUIT
The file naca0012.dat
can be found under sample_airfoils
directory from uncompressed construct2D archive or can be downloaded from this [link](https://gist.github.com/SignificantCell2/fd75765b9ffd45e880901564e990e2c3) .
The problem is that the command:
construct2d < instructions.txt
doesn't give the expected result when I run it only once, I have to run the command above several times (4 times maybe) to get the expected results: (the expected output is: naca0012.p3d
and naca0012.nmf
).
When I run construct2d
manually and type the options in instructions.txt
one by one, it works as expected. I've tried to use gdb
to debug that but unfrotunately it doesn't show anything special.
So it appears that the program is ignoring some instructions when feeded from a file. Why does this happen?
* The stdout output when the program runs as expected (in addition, the program will generate the output files: naca0012.p3d
and naca0012.nmf
): [working.log](https://gist.github.com/SignificantCell2/08103ec60378b0946a85b7db6811df16)
* The stdout output when the program doesn't run as exepcted (without output files): [not_working.log](https://gist.github.com/SignificantCell2/b375858378df10ebc078e396c311f1f5)
I greatly appreciate your help.
**EDIT 1**:
On Windows 10, with gfortran 8.1.0, file redirection works just fine, it doesn't fail. This happens only on Linux as I described above.
**EDIT2**: I confirm this has nothing to do with line endings. Because I've created the file instructions.txt
itself on Linux. And used dos2unix
tool to check the file.
**EDIT3**
I have tried compiling the program with older versions of gfortran (gfortran 7.5.0 on Ubuntu server 18.04) and everything works correctly. This might be a bug in newer versions of GNU Fortran.
**EDIT 4**:
I've solved that weird behaviour in gfortran 9.x and 10.x by adding the flag -Og
or -O0
when compiling the program.
Asked by adhrar_nmatrous
(85 rep)
Sep 16, 2020, 04:35 PM
Last activity: Sep 19, 2020, 04:31 AM
Last activity: Sep 19, 2020, 04:31 AM