Path: csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: pipe a buffer to a program's stdin using popen Date: Sat, 01 Jan 2022 15:00:38 -0800 Organization: None to speak of Lines: 21 Message-ID: <87fsq712p5.fsf@nosuchdomain.example.com> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: reader02.eternal-september.org; posting-host="431043dbf5bf54d703799e2d94f6f961"; logging-data="6243"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+BSI/CJ3SveGiU9Jxdc1Te" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:rNm3vODihgpHwRa00HQdljyhN+A= sha1:RYFaTf6mEVjH4Lj3bh90osTvgUc= Xref: csiph.com comp.lang.c:164209 John Forkosh writes: > 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. popen() is POSIX, not ISO C. Try comp.unix.programmer. -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Working, but not speaking, for Philips void Void(void) { Void(); } /* The recursive call of the void */