<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Yeah, I've got the standard parent writes to the child process down. That's not the issue. I've got to write to one process via a pipe. That process is not a process I'm writing, but an existing program. Again, check the example: <div><br></div><div>system("echo stuff | somebinary arg1 arg2");</div><div><br></div><div>The part I'm wrestling with is the:</div><div><br></div><div>echo stuff | somebinary<br><div><br><div><br></div><div><br><div><div>On Apr 5, 2013, at 7:56 PM, Ed Cashin wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr"><div>I was going to write this example before realizing it is probably online, and I found it here:<br><br><a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/pipe.html">http://pubs.opengroup.org/onlinepubs/9699919799/functions/pipe.html</a><br>
<br></div>... in the docs for standard pipe(2) behavior. It looks like the stuff after the ellipsis is in main or some other function whose beginning and end aren't shown.<br><br><pre><tt>#include <stdlib.h>
#include <unistd.h>
...
<br>
int fildes[2];
const int BSIZE = 100;
char buf[BSIZE];
ssize_t nbytes;
int status;
<br>
status = pipe(fildes);
if (status == -1 ) {
/* an error occurred */
...
}
<br>
switch (fork()) {
case -1: /* Handle error */
break;
<br>
case 0: /* Child - reads from pipe */
close(fildes[1]); /* Write end is unused */
nbytes = read(fildes[0], buf, BSIZE); /* Get data from pipe */
/* At this point, a further read would see end of file ... */
close(fildes[0]); /* Finished with pipe */
exit(EXIT_SUCCESS);
<br>
default: /* Parent - writes to pipe */
close(fildes[0]); /* Read end is unused */
write(fildes[1], "Hello world\n", 12); /* Write data on pipe */
close(fildes[1]); /* Child will see EOF */
exit(EXIT_SUCCESS);
}
</tt></pre><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Apr 5, 2013 at 3:33 PM, Geoffrey Myers <span dir="ltr"><<a href="mailto:lists@serioustechnology.com" target="_blank">lists@serioustechnology.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; position: static; z-index: auto; ">So, shaking some cobwebs loose here. How do I replace the following:<br>
<br>
system("echo stuff | somebinary arg1 arg2");<br>
<br>
With a fork/exec ??<br>
<br>
(Digging out my old C books....)<br>
<br>
--<br>
From my iPhone<br>
<span class="HOEnZb"><font color="#888888">Geoffrey Myers<br>
_______________________________________________<br>
Ale mailing list<br>
<a href="mailto:Ale@ale.org">Ale@ale.org</a><br>
<a href="http://mail.ale.org/mailman/listinfo/ale" target="_blank">http://mail.ale.org/mailman/listinfo/ale</a><br>
See JOBS, ANNOUNCE and SCHOOLS lists at<br>
<a href="http://mail.ale.org/mailman/listinfo" target="_blank">http://mail.ale.org/mailman/listinfo</a><br>
</font></span></blockquote></div><br><br clear="all"><br>-- <br> Ed Cashin <<a href="mailto:ecashin@noserose.net">ecashin@noserose.net</a>><br> <a href="http://noserose.net/e/">http://noserose.net/e/</a><br> <a href="http://www.coraid.com/">http://www.coraid.com/</a>
</div>
_______________________________________________<br>Ale mailing list<br><a href="mailto:Ale@ale.org">Ale@ale.org</a><br>http://mail.ale.org/mailman/listinfo/ale<br>See JOBS, ANNOUNCE and SCHOOLS lists at<br>http://mail.ale.org/mailman/listinfo<br></blockquote></div><br><div>
<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div>--</div><div>Until later, Geof</div><div><br></div></span><br class="Apple-interchange-newline">
</div>
<br></div></div></div></body></html>