How to disable "Press ENTER to continue"?

Hi Fortran experts,

In my Fortran code, a binary library module is being called to perform a specific calculation. However, for some sets of parameters, the calculation performed by this library does not converge, and the message “Press ENTER to continue” is displayed on the terminal. I would like to disable this message so that my program can proceed with other parameter sets without requiring user interaction. Unfortunately, since I do not have access to the source code of this library, I cannot modify or comment out this specific line. Is there a workaround, such as a way to automatically proceed if the “Press ENTER to continue” message is displayed on the terminal?

Thank you in advance for your help.
Mary

Does your program expect any other input from the keyboard?
If not, you can cheat it by preparing a dummy file with empty lines (at least as many of them as the number of “Press ENTER to continue” messages it may give) and then run the program with redirection:
progname < dummyfilename
This will work in any unix-like environment (Linux, MacOS) and probably even in MS Windows.

2 Likes

The program does not expect any other input from the keyboard.
Normally, if the calculation of this library converges, nothing will be asked to be given as input from the keyboard.
So, do you mean that the following command:

gfortran -o binary_myprogram test.F90 B.so
./binary_myprogram

should be modified into:

gfortran -o binary_myprogram test.F90 B.so
./binary_myprogram < dummyfilename

P.S.: I am using Linux.

@mary,

@msz59 has the right solution for you. You can likely test it yourself via a silly simulation in your environment as follows:

   real :: x
   call random_number(x)
   if ( abs(x-0.5) < 0.1 ) then
      print *, "Press ENTER to continue"
      read(*,*)
   end if
   stop
end 
  • so on Microsoft Windows, redirection of a dummy file to the program helps avoid the prompt for the user to respond to:
C:\temp>p.exe <junk.txt

C:\temp>p.exe <junk.txt

C:\temp>p.exe <junk.txt

C:\temp>p.exe <junk.txt
 Press ENTER to continue

C:\temp>

Thank you. You solved my problem.

thanks for your reply. I had written a test based on @msz59 comment but I was getting an error so I thought maybe ./binary_myprogram < dummyfilename should have been written differently. But the error was coming from the fact that I did not put enough empty lines in my text file. Anyway, thank you for providing an example :slight_smile:

As an FYI; the ULS command “yes” is designed for this, as in

      yes '' |myprogram
2 Likes