check_stdin_available Subroutine

public subroutine check_stdin_available(has_stdin)

Arguments

Type IntentOptional Attributes Name
logical, intent(out) :: has_stdin

Source Code

    subroutine check_stdin_available(has_stdin)
        logical, intent(out) :: has_stdin
        integer :: exit_status

        ! Use test command to check if STDIN is not a terminal
        ! test -t 0 returns true if STDIN is a terminal, false otherwise
        call execute_command_line('test ! -t 0', exitstat=exit_status)

        ! If exit_status is 0, STDIN is not a terminal (piped/redirected)
        has_stdin = (exit_status == 0)

    end subroutine check_stdin_available