public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "john.harper at vuw dot ac.nz" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libfortran/113313] execute_command_line hangs at run time
Date: Mon, 15 Jan 2024 20:40:46 +0000	[thread overview]
Message-ID: <bug-113313-4-GLEp6nWgbA@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-113313-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113313

--- Comment #9 from john.harper at vuw dot ac.nz ---
This variant of my test program (now called test4) hangs with gfortran 
but not with other compilers if iam is written to output_unit (like the 
original version) or to a file with a different positive unit number, but 
it does not hang if written to a file with a negative unit number obtained 
by opening it with newunit=u. Its user has those 3 choices at run time.

I hope it helps you explore this oddity of gfortran.

program test4
   use iso_fortran_env, only: output_unit
! Linux with f2008 (newunit=, execute_command_line, allocatable scalar)
   implicit none
   integer:: u = output_unit+20
   character:: ch*1, line(2)*80
   print "(A)",'Output from iam will go to unit u;', &
        ' u=output_unit if you enter a, or',&
        ' unit=u (u>0)  if you enter b, or',&
        ' newunit=u (u<0) if you enter anything else.'
   read "(A)", ch
   if(ch=='a') then
      u = output_unit
   else if(ch=='b') then
      open(   unit=u,file='test4.out')
   else
      open(newunit=u,file='test4.out')
   end if
   print "(A,I0)",'Output from iam will be written to unit ',u
   write(u,"(A,L2)")'I am john',iam('john')
   write(u,"(A,L2)")'I am JOHN',iam('JOHN')
   if(u/=output_unit) then
      rewind u
      read(u,"(A)") line
      print  "(A)", line
      close(u,status='delete')
   end if
contains

   logical function iam(      name)
     character(*),intent(in)::name
     integer estat
     character(:),allocatable:: cmd
     cmd = 'if [ `whoami` != "'//name//'" ]; then exit 1; else exit 0; fi'
     call execute_command_line(cmd,exitstat=estat)
     iam = (estat==0)
   end function iam
end program test4

-- John Harper, School of Mathematics and Statistics
Victoria Univ. of Wellington, PO Box 600, Wellington 6140, New Zealand.
e-mail john.harper@vuw.ac.nz

      parent reply	other threads:[~2024-01-15 20:40 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-10 20:20 [Bug fortran/113313] New: " john.harper at vuw dot ac.nz
2024-01-11  5:49 ` [Bug libfortran/113313] " kargl at gcc dot gnu.org
2024-01-11  7:03 ` john.harper at vuw dot ac.nz
2024-01-11  7:17 ` john.harper at vuw dot ac.nz
2024-01-11 20:18 ` jvdelisle at gcc dot gnu.org
2024-01-11 20:45 ` kargl at gcc dot gnu.org
2024-01-11 22:40 ` john.harper at vuw dot ac.nz
2024-01-12 20:02 ` sgk at troutmask dot apl.washington.edu
2024-01-13  3:42 ` jvdelisle at gcc dot gnu.org
2024-01-15 20:40 ` john.harper at vuw dot ac.nz [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-113313-4-GLEp6nWgbA@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).