1
votes

I can pass the input file to fortran program, like this:

./foo < inputfile

But in gdb, I tried this:

gdb ./foo
run < inputfile

It displays nothing and doesn't work.

Update: My system is MACOS high sierra GDB version: 8.0

2
That should work fine. Your OS may matter, and you may have something in your ~/.bashrc or other shell startup script that prevents it from working. - Employed Russian
I tried to remove the .bach_profile, but the problem is still there. Thank you for your advice. - Steve
I'll ask you again, more directly: please edit your question with: what OS are you running, what version of GDB? Any other details about your environment that you can reveal might prove helpful. As is, your question is devoid of all relevant details, and you are unlikely to receive help. - Employed Russian
I met the same trouble but on Windows only. To overcome it, I now use the intrinsic subroutine get_command_argument to get the name of the input file. Then, with gdb, the command run inputfile works perfectly ! - Francois Jacq
@FrancoisJacq Can you give me an example? It might solve my problem. Thanks - Steve

2 Answers

0
votes

Example of main program getting optionally an input data file from argument :

program test
   character(256) :: cfile
   integer :: unit,status,itest
   call get_command_argument(1,cfile)
   if(cfile /= "") then
      unit=15
      open(unit,file=cfile,iostat=status)
      if(status /= 0) then
         write(*,*) 'invalid file ',trim(cfile)
         stop
      endif
   else
      unit=5
   endif
   read(unit,*) itest
   write(*,*) itest
   ! ...
end program

Input deck "d.dat" :

25

Test :

[coul@localhost ~]$ gfortran -g test.f90
[coul@localhost ~]$ ./a.out < d.dat
          25
[coul@localhost ~]$ gdb a.out
GNU gdb (GDB) Fedora 7.10.1-31.fc23
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
(gdb) run d.dat
Starting program: /home/coul/a.out d.dat
          25
(gdb) 
-1
votes

Maybe try run <<< $(cat file)