1

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!

3
  • Does using ./fortran_file.x instead work? Commented Sep 29, 2019 at 3:52
  • yes, that works. Commented Sep 29, 2019 at 4:25
  • @Shawn it seems that even just running timeout 2s fortran_file.x give this error: timeout: failed to run command ‘fortran_file.x’: No such file or directory Commented Sep 29, 2019 at 5:31

1 Answer 1

1

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).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.