<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>I had tried something like that before. &nbsp;Still didnt work. Turns out, the program must be looking at the real uid as it returns a 'not authorized error'. Thanks for the assistance.&nbsp;<br><br><div>--</div><div>From my iP<span class="Apple-style-span" style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.296875); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469); ">hone</span></div><div>Geoffrey Myers</div></div><div><br>On Apr 7, 2013, at 7:40 PM, David Tomaschik &lt;<a href="mailto:david@systemoverlord.com">david@systemoverlord.com</a>&gt; wrote:<br><br></div><div><span></span></div><blockquote type="cite"><div><div dir="ltr"><span style="font-family:arial,sans-serif;font-size:13px">set up a pipe, fork(), dup2(pipe_output, STDIN); exec(), (from parent process) push "stuff" into pipe should work for that.</span><br><div>
<span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div style=""><span style="font-family:arial,sans-serif;font-size:13px">Something like:</span></div><div style=""><span style="font-family:arial,sans-serif;font-size:13px">(Please add error checking...)</span></div>
<div style=""><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div style=""><span style="font-family:arial,sans-serif;font-size:13px">pid_t child;</span></div><div style=""><span style="font-family:arial,sans-serif;font-size:13px">int pipefd[2];</span></div>
<div style=""><span style="font-family:arial,sans-serif;font-size:13px">char stuff[] = "stuff";</span></div><div style=""><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div style=""><span style="font-family:arial,sans-serif;font-size:13px">pipe(pipefd);</span></div>
<div style=""><span style="font-family:arial,sans-serif;font-size:13px">if((child = fork()) == 0) {</span></div><div style=""><font face="arial, sans-serif">&nbsp; // Child</font></div><div style=""><font face="arial, sans-serif">&nbsp; dup2(pipefd[0], STDIN_FILENO);</font></div>
<div style=""><font face="arial, sans-serif">&nbsp; execl("/bin/foo", "/bin/foo", "--some-arg");</font></div><div style=""><font face="arial, sans-serif">}</font></div><div style=""><font face="arial, sans-serif">write(pipefd[1], stuff, strlen(stuff));</font></div>
<div style=""><font face="arial, sans-serif">waitpid(child, ...);</font></div><div style=""><font face="arial, sans-serif"><br></font></div><div style=""><font face="arial, sans-serif">(Haven't tested it, but this should work...)</font></div>
<div style=""><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div style=""><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Sun, Apr 7, 2013 at 4:03 PM, Geoffrey Myers <span dir="ltr">&lt;<a href="mailto:lists@serioustechnology.com" target="_blank">lists@serioustechnology.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word">Yeah, I've got the standard parent writes to the child process down. &nbsp;That's not the issue. &nbsp;I've got to write to one process via a pipe. &nbsp;That process is not a process I'm writing, but an existing program. &nbsp;Again, check the example:&nbsp;<div class="im">
<div><br></div><div>system("echo stuff | somebinary arg1 arg2");</div><div><br></div></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><div><div class="h5"><br><div><div>On Apr 5, 2013, at 7:56 PM, Ed Cashin wrote:</div><br><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" target="_blank">http://pubs.opengroup.org/onlinepubs/9699919799/functions/pipe.html</a><br>
<br></div>... in the docs for standard pipe(2) behavior.&nbsp; 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 &lt;stdlib.h&gt;
#include &lt;unistd.h&gt;
...
<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">&lt;<a href="mailto:lists@serioustechnology.com" target="_blank">lists@serioustechnology.com</a>&gt;</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">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><font color="#888888">Geoffrey Myers<br>
_______________________________________________<br>
Ale mailing list<br>
<a href="mailto:Ale@ale.org" target="_blank">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>&nbsp; Ed Cashin &lt;<a href="mailto:ecashin@noserose.net" target="_blank">ecashin@noserose.net</a>&gt;<br>&nbsp; <a href="http://noserose.net/e/" target="_blank">http://noserose.net/e/</a><br>
&nbsp; <a href="http://www.coraid.com/" target="_blank">http://www.coraid.com/</a>
</div>
_______________________________________________<br>Ale mailing list<br><a href="mailto:Ale@ale.org" target="_blank">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></blockquote></div><br></div></div><div>
<span style="text-indent:0px;letter-spacing:normal;font-variant:normal;text-align:auto;font-style:normal;font-weight:normal;line-height:normal;border-collapse:separate;text-transform:none;font-size:medium;white-space:normal;font-family:Helvetica;word-spacing:0px"><div>
--</div><div>Until later, Geof</div><div><br></div></span><br>
</div>
<br></div></div></div></div><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>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br>David Tomaschik<br>OpenPGP: 0x5DEA789B<br><a href="http://systemoverlord.com" target="_blank">http://systemoverlord.com</a><br><a href="mailto:david@systemoverlord.com" target="_blank">david@systemoverlord.com</a>
</div>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>Ale mailing list</span><br><span><a href="mailto:Ale@ale.org">Ale@ale.org</a></span><br><span><a href="http://mail.ale.org/mailman/listinfo/ale">http://mail.ale.org/mailman/listinfo/ale</a></span><br><span>See JOBS, ANNOUNCE and SCHOOLS lists at</span><br><span><a href="http://mail.ale.org/mailman/listinfo">http://mail.ale.org/mailman/listinfo</a></span><br></div></blockquote></body></html>