[UP]


Manual Reference Pages  - process_writeline (3)

NAME

process_writeline(3fm) - [M_process] write to a process using a POSIX interface (LICENSE:PD)

CONTENTS

Synopsis
Description
Options
Examples
See Also
Author
License

SYNOPSIS

subroutine process_writeline(string,fp,ierr)

      character(len=*)    :: string
      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

string data line to to process
fp C file pointer returned by process_open_*()
ierr error flag returned.
o process_writeline(3f) : negative indicates an error
o process_readline(3f) : Non-zero indicates an error
maximum character value length is currently 4096

EXAMPLES

This example shows a routine to write lines to the stdin of a system process

  program demo_process_writeline
  use, intrinsic :: iso_fortran_env, only : &
     & stdin=>input_unit, &
     & stdout=>output_unit, &
     & stderr=>error_unit
  use m_process ,only: process_open_write, process_writeline
  use m_process ,only: streampointer, process_close
  implicit none
  type(streampointer) :: fp
  ! line of data to write
  character(len=4096) :: line
  integer             :: ierr
  integer             :: i
    ! open process to write to
    call process_open_write(’cat -n’,fp,ierr)
    write(*,*)’WRITETEST: process is opened with status ’,ierr
    ! remember C and Fortran I/O are often independent of each other
    flush(stdout)
    ierr=0
    line=’xxxxxxxxxxxxxxxxxxxxxxxxxxx’
    do i=1,10
      ! write a line to the process
      call process_writeline(trim(line),fp,ierr)
      if(ierr.lt.0)then
        write(*,*)’WRITETEST: ierr is ’,ierr
        exit
      endif
    enddo
    call process_close(fp,ierr)
    write(*,*)’WRITETEST: process closed with status ’,ierr
  end program demo_process_writeline

Sample output:

  >WRITETEST: process is opened with status            0
  >   1 xxxxxxxxxxxxxxxxxxxxxxxxxxx
  >   2 xxxxxxxxxxxxxxxxxxxxxxxxxxx
  >   3 xxxxxxxxxxxxxxxxxxxxxxxxxxx
  >   4 xxxxxxxxxxxxxxxxxxxxxxxxxxx
  >   5 xxxxxxxxxxxxxxxxxxxxxxxxxxx
  >   6 xxxxxxxxxxxxxxxxxxxxxxxxxxx
  >   7 xxxxxxxxxxxxxxxxxxxxxxxxxxx
  >   8 xxxxxxxxxxxxxxxxxxxxxxxxxxx
  >   9 xxxxxxxxxxxxxxxxxxxxxxxxxxx
  >  10 xxxxxxxxxxxxxxxxxxxxxxxxxxx
  >WRITETEST: process closed with status            0

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


process_writeline (3) March 11, 2021
Generated by manServer 1.08 from 5ef01971-9b6e-49fd-a2fd-9c02b0099486 using man macros.