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


Groups > comp.lang.c > #164217

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 09:34 +0000
Organization PANIX Public Access Internet and UNIX, NYC
Message-ID <sqrriq$k2e$2@reader1.panix.com> (permalink)
References <sqp79k$po6$1@reader1.panix.com> <0d5a369b-6e89-4b1b-9769-812406e84b05n@googlegroups.com>

Show all headers | View raw


Mark Bluemel <mark.bluemel@gmail.com> wrote:
> John Forkosh wrote:
>> Suppose I have a program that, in part, runs another program 
>> using FILE *outptr=popen("some command string","r") and then 
>> fread()'s its stdout from outptr. Now, if that other program 
>> is otherpgm which reads input from its stdin, and I also want 
>> that input to come from a file inputfile, then I could easily 
>> just write FILE *outptr=popen("cat inputfile|otherpgm","r"); 
>> 
>> But here's the rub: rather than some inputfile on disk, my 
>> program has an internal unsigned char buffer[9999] which is 
>> what I want piped to otherpgm, but which I don't want written 
>> to disk first. How can I get buffer piped to otherpgm's stdin 
>> using popen()? Or some other mechanism, as long as I can read 
>> otherpgm's stdout from within my program. 
>> -- 
>> John Forkosh ( mailto: j...@f.com where j=john and f=forkosh )
> popen() is part of the POSIX spec, I believe. 
> 
> This is possibly better suited to comp.unix.programming
> or a similar newsgroup. I'd probably dig out a copy of
> https://en.wikipedia.org/wiki/Advanced_Programming_in_the_Unix_Environment
> and remind myself how to do this sort of thing.
> It would probably involve fork/exec and explicit pipe management.

Thanks, Mark. Yeah, I actually have a hardback paper copy of APUE,
purchased in the 1990's. I've only occasionally (very occasionally)
used fork, etc, and couldn't quite figure out how to do what I want
from Chapters 14 and 15. The answer may well be there, but I couldn't
quite figure it out.
-- 
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