• Redirectiong standard error

    From Daniel Feenberg@21:1/5 to All on Wed Sep 8 11:57:19 2021
    Is there a way within fortran to direct unit 0 (error output) to a file? Particularly I want to redirect it to standard out. I am hoping for something within Fortran that would be portable across major operating systems. I did try
    open(unit=0,file="stuff")
    and
    open(unit=0,file='/dev/tty')
    with gfortran under Linux, but the open statement seemed to have no effect.

    Daniel Feenberg
    NBER

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From steve kargl@21:1/5 to Daniel Feenberg on Wed Sep 8 20:07:02 2021
    Daniel Feenberg wrote:

    Is there a way within fortran to direct unit 0 (error output) to a file? Particularly I want to redirect it to standard out. I am hoping for something within Fortran that would be portable across major operating systems. I did try
    open(unit=0,file="stuff")
    and
    open(unit=0,file='/dev/tty')
    with gfortran under Linux, but the open statement seemed to have no effect.

    Daniel Feenberg
    NBER

    You can try to close ERROR_UNIT from ISO_FORTRAN_ENV
    and then re-use that unit number. Not sure if it works.

    program foo
    use iso_fortran_env
    close(ERROR_UNIT)
    open(unit=ERROR_UNIT,file=....)
    end program foo

    --
    steve

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Daniel Feenberg@21:1/5 to steve kargl on Wed Sep 8 14:15:07 2021
    On Wednesday, September 8, 2021 at 4:07:05 PM UTC-4, steve kargl wrote:
    Daniel Feenberg wrote:

    Is there a way within fortran to direct unit 0 (error output) to a file? Particularly I want to redirect it to standard out. I am hoping for something within Fortran that would be portable across major operating systems. I did try
    ...
    You can try to close ERROR_UNIT from ISO_FORTRAN_ENV
    and then re-use that unit number. Not sure if it works.

    program foo
    use iso_fortran_env
    close(ERROR_UNIT)
    open(unit=ERROR_UNIT,file=....)
    end program foo

    --
    steve
    Just tried it out in gfortran Linux and FreeBSD - no effect on the destination of error output. I did want to avoid depending on the shell for this because different shells have different syntax for this, and I don't want to explain that to users or tell
    them which shell to use.
    Daniel Feenberg

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From steve kargl@21:1/5 to Daniel Feenberg on Wed Sep 8 23:11:48 2021
    Daniel Feenberg wrote:

    On Wednesday, September 8, 2021 at 4:07:05 PM UTC-4, steve kargl wrote:
    Daniel Feenberg wrote:

    Is there a way within fortran to direct unit 0 (error output) to a file? Particularly I want to redirect it to standard out. I am hoping for something within Fortran that would be portable across major operating systems. I did try
    ...
    You can try to close ERROR_UNIT from ISO_FORTRAN_ENV
    and then re-use that unit number. Not sure if it works.

    program foo
    use iso_fortran_env
    close(ERROR_UNIT)
    open(unit=ERROR_UNIT,file=....)
    end program foo

    --
    steve
    Just tried it out in gfortran Linux and FreeBSD - no effect on the destination of error output. I did want to avoid depending on the shell for this because different shells have different syntax for this, and I don't want to explain that to users or
    tell them which shell to use.
    Daniel Feenberg

    Gfortran has an environmental variable that allows one to change the unit
    to some other value, but suspect that doesn't change the internal use of
    stderr (as found in C). Even if an EV worked, you would to users how to
    an EV for the different shells.

    --
    steve

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Steve Lionel@21:1/5 to Daniel Feenberg on Wed Sep 8 19:05:58 2021
    On 9/8/2021 2:57 PM, Daniel Feenberg wrote:
    Is there a way within fortran to direct unit 0 (error output) to a file?

    There are two different things at work here. Unit 0 (or whatever
    ERROR_UNIT is defined as) is often "preconnected" to stderr. You are
    free to reopen that unit on a file, but it is no longer "error output".
    Any output that would normally go to stderr, other than explicit writes
    to unit 0, will still go to stderr.

    The only way I know of to do the redirection you seek is to do it on the command line invoking the program.

    --
    Steve Lionel
    ISO/IEC JTC1/SC22/WG5 (Fortran) Convenor
    Retired Intel Fortran developer/support
    Email: firstname at firstnamelastname dot com
    Twitter: @DoctorFortran
    LinkedIn: https://www.linkedin.com/in/stevelionel
    Blog: https://stevelionel.com/drfortran
    WG5: https://wg5-fortran.org

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From gah4@21:1/5 to steve kargl on Wed Sep 8 18:36:21 2021
    On Wednesday, September 8, 2021 at 4:11:50 PM UTC-7, steve kargl wrote:

    (snip)
    Gfortran has an environmental variable that allows one to change the unit
    to some other value, but suspect that doesn't change the internal use of stderr (as found in C). Even if an EV worked, you would to users how to
    an EV for the different shells.

    You can change an EV within the program. Exactly when its value is needed, isn't so obvious. It might be not read until an actual I/O operations is needed.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Gary Scott@21:1/5 to All on Thu Sep 9 05:00:57 2021
    On 9/8/2021 8:36 PM, gah4 wrote:
    On Wednesday, September 8, 2021 at 4:11:50 PM UTC-7, steve kargl wrote:

    (snip)
    Gfortran has an environmental variable that allows one to change the unit
    to some other value, but suspect that doesn't change the internal use of
    stderr (as found in C). Even if an EV worked, you would to users how to
    an EV for the different shells.

    You can change an EV within the program. Exactly when its value is needed, isn't so obvious. It might be not read until an actual I/O operations is needed.

    Depends on the operating system.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From gah4@21:1/5 to All on Thu Sep 9 06:31:23 2021
    On Thursday, September 9, 2021 at 3:01:00 AM UTC-7, Gary Scott wrote:

    (snip, I wrote)
    You can change an EV within the program. Exactly when its value is needed, isn't so obvious. It might be not read until an actual I/O operations is needed.

    Depends on the operating system.

    OK, back to the start.

    As it says above: "I did want to avoid depending on the shell for this because
    different shells have different syntax for this, and I don't want to explain
    that to users or tell them which shell to use."

    That happens if one asks the user to add variables to the system.

    But the other way is to supply a shell script that the user runs, which then runs
    the actual program. Unix-like systems run such in a Bourne (sh) shell, unless told
    otherwise, independent of the user's actual shell. It does that just for the reason
    given: that it works independent of the user's actual shell.

    (Except that csh and descendants, if it starts with # and not #!, will run it in a shell like itself.)

    The other other way is to start with #! and the path of a program (shell)
    to use to run it.

    Of course DOS/Windows use a different system, but the executable file has
    to be different, too.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)