Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #164225

Re: pipe a buffer to a program's stdin using popen

From John Forkosh <forkosh@panix.com>
Newsgroups comp.lang.c
Subject Re: pipe a buffer to a program's stdin using popen
Date 2022-01-02 18:00 +0000
Organization PANIX Public Access Internet and UNIX, NYC
Message-ID <sqsp80$fmk$2@reader1.panix.com> (permalink)
References <sqp79k$po6$1@reader1.panix.com> <sqs7a1$o59$1@dont-email.me> <sqseaq$2ko37$1@news.xmission.com>

Show all headers | View raw


Kenny McCormack <gazelle@shell.xmission.com> wrote:
> Lew Pitcher  <lew.pitcher@digitalfreehold.ca> wrote:
> ...
>>Assuming a Unix-like environment,
>>  pipe() to create a pair of unidirectional pipes
>>  fork() to create a child process
>>  in parent, close() the [0] pipe, and write() your data to the [1] pipe
>>  in child, close(STDIN_FILENO), dup() the [1] pipe, and then exec() your
>>     target "some command string" executable
> 
> The problem with this is that, as Kaz alluded to, pipes are only guaranteed
> to be at least 4096 bytes in size - and deadlock is possible.  The original
> post suggested that the input string was about 10K (which is already too
> big) in size, but subsequent followups by OP have stated that it could be
> multi-megabytes.  So, you can't just shove it all into the pipe in one go
> (w/o having the reader be reading some of it as you go).

Yeah, definitely can be multi-MB input to stdin (when I originally
wrote "unsigned char buffer[9999]", I hadn't meant to imply that as
a maximum). Thanks for the additional warning, and I'll explicitly
look for that discussion while munging through APUE again.

> Also, OP was using popen() to encapsulate the gory details of
> pipe/fork/dup/exec. Going this route, he would lose the
> simplicity/elegance of popen().

Yeah, I already pretty much figured out from the preceding discussion
that "lose the simplicity/elegance" was a foregone conclusion.
-- 
John Forkosh  ( mailto:  j@f.com  where j=john and f=forkosh )

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

pipe a buffer to a program's stdin using popen John Forkosh <forkosh@panix.com> - 2022-01-01 09:35 +0000
  Re: pipe a buffer to a program's stdin using popen Mark Bluemel <mark.bluemel@gmail.com> - 2022-01-01 03:22 -0800
    Re: pipe a buffer to a program's stdin using popen Meredith Montgomery <mmontgomery@levado.to> - 2022-01-01 11:21 -0300
    Re: pipe a buffer to a program's stdin using popen John Forkosh <forkosh@panix.com> - 2022-01-02 09:34 +0000
  Re: pipe a buffer to a program's stdin using popen Kaz Kylheku <480-992-1380@kylheku.com> - 2022-01-01 19:51 +0000
    Re: pipe a buffer to a program's stdin using popen gazelle@shell.xmission.com (Kenny McCormack) - 2022-01-01 21:00 +0000
      Re: pipe a buffer to a program's stdin using popen John Forkosh <forkosh@panix.com> - 2022-01-02 09:12 +0000
    Re: pipe a buffer to a program's stdin using popen John Forkosh <forkosh@panix.com> - 2022-01-02 09:30 +0000
      Re: pipe a buffer to a program's stdin using popen Kaz Kylheku <480-992-1380@kylheku.com> - 2022-01-03 00:03 +0000
        Re: pipe a buffer to a program's stdin using popen John Forkosh <forkosh@panix.com> - 2022-01-03 08:07 +0000
          Re: pipe a buffer to a program's stdin using popen Manfred <noname@add.invalid> - 2022-01-03 22:54 +0100
  Re: pipe a buffer to a program's stdin using popen Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-01-01 15:00 -0800
    Re: pipe a buffer to a program's stdin using popen gazelle@shell.xmission.com (Kenny McCormack) - 2022-01-02 00:01 +0000
  Re: pipe a buffer to a program's stdin using popen Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2022-01-02 12:54 +0000
    Re: pipe a buffer to a program's stdin using popen gazelle@shell.xmission.com (Kenny McCormack) - 2022-01-02 14:54 +0000
      Re: pipe a buffer to a program's stdin using popen Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2022-01-02 15:37 +0000
      Re: pipe a buffer to a program's stdin using popen John Forkosh <forkosh@panix.com> - 2022-01-02 18:00 +0000
        Re: pipe a buffer to a program's stdin using popen gazelle@shell.xmission.com (Kenny McCormack) - 2022-01-02 18:03 +0000
    Re: pipe a buffer to a program's stdin using popen John Forkosh <forkosh@panix.com> - 2022-01-02 17:51 +0000

csiph-web