Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash stderr and stdout redirection failing

Tags:

bash

fortran

I have a FORTRAN program output I want to redirect to file. I've done this before and use

$myprog.out>>out.txt 2>&1

and for some reason this is not working. I test it with a another simple test program

$myprog.test>>out.txt 2>&1

and it works

I run myprog.out and the output goes to screen as usual but redirecting it seems to fail! It was working and now seems to have stopped working. It's very strange. I commented out a few print statements that I no longer wanted, recompiled and then band redirect does not work.

There is clearly something different going on with my output but how to diagnose where it is going?

like image 654
Tommy Avatar asked Oct 23 '25 18:10

Tommy


1 Answers

You probably need to flush your output. See for example this SO topic. How to do that depends on your compiler I guess. Because only Fortran 2003 Standard includes flush() statement and the ability to determine numbers that corresponds to stdout/stderr units.

However in gfortran (for example) you can use flush() intrinsic procedure with the equivalents of Unix file descriptors: UNIT=5 for stdin, UNIT=6 for stdout and UNIT=0 for stderr.

PROGRAM main

  PRINT *, "Hello!"
  CALL flush(6)
  CALL flush(0)

END PROGRAM main
like image 125
Wildcat Avatar answered Oct 26 '25 07:10

Wildcat