Provided by: manpages-es-dev_4.18.1-1_all bug

NOMBRE

       popen, pclose - flujo desde o hacia un proceso

BIBLIOTECA

       Biblioteca Estándar C (libc, -lc)

SINOPSIS

       #include <stdio.h>

       FILE *popen(const char *orden, const char *tipo);
       int pclose(FILE *flujo);

   Requisitos de Macros de Prueba de Características para glibc (véase feature_test_macros(7)):

       popen(), pclose():
           _POSIX_C_SOURCE >= 2
               || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE

DESCRIPCIÓN

       La  función  popen() inicia un proceso creando una tubería, llamando a fork(2)  para crear
       el proceso y ejecutando el intérprete de órdenes  (shell).   Puesto  que  una  tubería  es
       unidireccional  por  definición,  el  argumento  tipo  sólo  puede  especificar  lectura o
       escritura, pero no ambos; el flujo resultante es respctivamente  de  lectura  o  escritura
       exclusiva.

       El  argumento orden es un puntero a una cadena terminada en cero que contiene una línea de
       orden del shell. Esta orden se pasa a /bin/sh precedida de la opción -c;  si  se  necesita
       interpretar la línea, esto lo hace el shell.

       The  type  argument is a pointer to a null-terminated string which must contain either the
       letter 'r' for reading or the letter 'w' for writing.  Since glibc 2.9, this argument  can
       additionally  include the letter 'e', which causes the close-on-exec flag (FD_CLOEXEC)  to
       be set on the underlying file descriptor; see the description of  the  O_CLOEXEC  flag  in
       open(2)  for reasons why this may be useful.

       The  return  value from popen()  is a normal standard I/O stream in all respects save that
       it must be closed with pclose()  rather than fclose(3).  Writing to such a  stream  writes
       to the standard input of the command; the command's standard output is the same as that of
       the  process  that  called  popen(),  unless  this  is  altered  by  the  command  itself.
       Conversely, reading from the stream reads the command's standard output, and the command's
       standard input is the same as that of the process that called popen().

       Note that output popen()  streams are block buffered by default.

       La función pclose() espera que el proceso asociado termine, y devuelve el estado de salida
       de la orden como el devuelto por wait4(2).

VALOR DEVUELTO

       popen(): on success, returns a pointer to an open stream that can be used to read or write
       to the pipe; if the fork(2)  or pipe(2)  calls fail, or if the  function  cannot  allocate
       memory, NULL is returned.

       pclose():  on  success,  returns  the  exit status of the command; if wait4(2)  returns an
       error, or some other error is detected, -1 is returned.

       On failure, both functions set errno to indicate the error.

ERRORES

       The popen()  function does not set errno if memory allocation fails.   If  the  underlying
       fork(2)   or  pipe(2)  fails, errno is set to indicate the error.  If the type argument is
       invalid, and this condition is detected, errno is set to EINVAL.

       Si pclose() no puede obtener el estado del hijo, se asigna a errno el valor ECHILD.

ATRIBUTOS

       Para obtener una explicación de los términos usados en esta sección, véase attributes(7).

       ┌────────────────────────────────────────────────┬────────────────────┬───────────────────┐
       │InterfazAtributoValor             │
       ├────────────────────────────────────────────────┼────────────────────┼───────────────────┤
       │popen(), pclose()                               │ Seguridad del hilo │ Multi-hilo seguro │
       └────────────────────────────────────────────────┴────────────────────┴───────────────────┘

ESTÁNDARES

       POSIX.1-2001, POSIX.1-2008.

       The 'e' value for type is a Linux extension.

NOTAS

       Note: carefully read Caveats in system(3).

ERRORES

       Puesto que la entrada estándar de una orden abierta para lectura comparte  su  puntero  de
       posición  con  el proceso que llamó a popen(), si el proceso original ha hecho una lectura
       tamponada, la posición en la entrada de la orden  puede  no  ser  la  esperada.  De  forma
       similar,  la salida de una orden abierta para escritura puede resultar mezclada con la del
       proceso original. Esto último puede evitarse llamando a fflush(3)  antes de a popen().

       Un fallo al ejecutar el shell es indistinguible de un  fallo  del  shell  al  ejecutar  la
       orden, o una salida inmediata de la orden. La única pista es un estado de salida 127.

VÉASE TAMBIÉN

       sh(1), fork(2), pipe(2), wait4(2), fclose(3), fflush(3), fopen(3), stdio(3), system(3)

TRADUCCIÓN

       La  traducción  al  español  de  esta  página del manual fue creada por Gerardo Aburruzaga
       García <gerardo.aburruzaga@uca.es>, Juan Piernas  <piernas@ditec.um.es>  y  Marcos  Fouces
       <marcos@debian.org>

       Esta  traducción  es  documentación  libre;  lea  la  GNU General Public License Version 3
       ⟨https://www.gnu.org/licenses/gpl-3.0.html⟩ o posterior con respecto a las condiciones  de
       copyright.  No existe NINGUNA RESPONSABILIDAD.

       Si  encuentra  algún  error  en  la  traducción de esta página del manual, envíe un correo
       electrónico a ⟨debian-l10n-spanish@lists.debian.org⟩.