I want to run some fortran code from a shell script on CentOS linux. I compiled the fortran file like this: gfortran -ffixed-line-length-none -O3 -o fortran_file.x fortran_file.f and then, in a .scr file I have this line of code: timeout {$maxtime}s fortran_file.x, where maxtime is passed as an external parameter. The code worked well on another computer, so i am quite confident I have no (major) bug, but when I run my .scr code as ./code.scr I am getting this error: timeout: failed to run command ‘fortran_file.x’: No such file or directory, althoug the fortran_file.x is obviously in the same directory as my .scr code. Does anyone know how can I fix this? Thank you!
1 Answer
The program timeout will just perform the command that you give it:
NAME
timeout - run a command with a time limit
SYNOPSIS
timeout [OPTION] DURATION COMMAND [ARG]...
timeout [OPTION]
DESCRIPTION
Start COMMAND, and kill it if still running after DURATION.
Your command is simply
fortran_file.x
This will start your program only when it can be found in the executable search path ($PATH). Apparently, this is not the case. So you either need to add your working directory to $PATH,
export PATH="$(pwd):$PATH"
or, better, just use ./ to refer to a program in your working directory,
timeout {$maxtime}s ./fortran_file.x
If your original line worked in some other system, it must have been either because the working directory was in $PATH, or due to some rather atypical shell that interpreted the command to your expectations (Windows do that, for instance).
./fortran_file.xinstead work?