process_close Subroutine

public subroutine process_close(fp, ierr)

NAME

process_close(3fm) - [M_process] close a process being written to
or read from
(LICENSE:PD)

SYNOPSIS

 subroutine process_close(fp,ierr)

   type(streampointer) :: fp
   integer             :: ierr

DESCRIPTION

The M_process Fortran procedures use the ISO_C_BINDING interface to define Fortran-callable versions of the C procedures popen(3c)/pclose(3c) and fgets(3c)/fputs(3c). A set of record-oriented wrapper routines are then used to create a simple Fortran-callable interface.

A POSIX C interface is generally available but may require using a Linux subwindow or an application such as CygWin on MSWindows platforms.

See “M_process” for an extended description.

OPTIONS

fp       C file pointer returned by process_open_*()
ierr     error flag returned.

EXAMPLES

This example shows a simple open and close of a process

program demo_process_close use M_process ,ONLY: process_open_read, process_open_write use M_process ,ONLY: streampointer, process_close implicit none type(streampointer) :: fp integer :: ierr ! open process to read from call process_open_read(‘ls -l’,fp,ierr) write(,)’CLOSE : process is opened with status ‘,ierr call process_close(fp,ierr) write(,)’CLOSE : process closed with status ‘,ierr end program demo_process_close

Sample output:

 CLOSE   : process is opened with status            0
 CLOSE   : process closed with status           13

SEE ALSO

o PIPES: pipe(3c), popen(3c), pclose(3c), fflush(3c)
o NAMED PIPES: mkfifo(3c), mknod(3c)
o SUBPROCESSES: fork(3c)
o OTHER: fflush(3c)

AUTHOR

John S. Urban

LICENSE

Public Domain

Arguments

Type IntentOptional Attributes Name
type(streampointer) :: fp
integer, intent(out) :: ierr

Contents

Source Code


Source Code

subroutine process_close(fp,ierr)

! ident_5="@(#)M_process::process_close(3f): close process"

! file pointer returned for process ! DO NOT MAKE fp INTENT(IN)
type(streampointer) :: fp
integer(c_int)      :: ios
integer,intent(out) :: ierr
!-------------------------------------------------------------------------------
   ios=0_c_int

   if (.not.c_associated(fp%handle)) then
      write(*,*)'*process_close* process not found'
   else
      ios=fflush(fp%handle)
      if(ierr.ge.0)then
         ios=system_pclose(fp%handle)
      endif
   endif

   if(process_debug)then
      write(*,*) '*process_close* Closed pipe with status ',ios
   endif

   ierr=ios

end subroutine process_close