# Returning a pipe?

**URL:** <https://www.ruby-forum.com/t/returning-a-pipe/196454>\
**Category:** Ruby\
**Created:** [September 4, 2007, 7:37pm UTC](https://www.ruby-forum.com/t/returning-a-pipe/196454 "2007-09-04T19:37:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![unbewusst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/ba9def/32.png) [@unbewusst](https://www.ruby-forum.com/u/unbewusst)\
**Post date:** [September 4, 2007, 7:37pm UTC](https://www.ruby-forum.com/t/returning-a-pipe/196454/1 "2007-09-04T19:37:14Z")

</div>

i’m writting a RubyCocoa application for synchronizing folders of a  
computer to folders of an usb key.

to let the user not bored, because it could takes time, i have a log  
window where i print the messages coming from rsync.

on another side, i need the call to rsync to have root privileges,  
then i’m writing a tinu ruby module in C to get the root privileges  
for rsync.

the way it is done, for the time being :

C side:  
±----+

if ( myStatus != errAuthorizationSuccess ) break;  
{  
FILE \*myCommunicationsPipe = NULL;  
char myReadBuffer[LINE\_MAX];

myFlags = kAuthorizationFlagDefaults;

myStatus = AuthorizationExecuteWithPrivileges( myAuthorizationRef,  
myToolPath, myFlags,  
myArguments,  
&myCommunicationsPipe );  
if ( bufferOut != NULL )  
{  
if ( myStatus == errAuthorizationSuccess )  
{  
int i = 0;  
int len;  
while ( fgets( myReadBuffer, LINE\_MAX, myCommunicationsPipe ) )  
{  
bufferOut[i] = strdup( myReadBuffer );  
len = strlen( bufferOut[i] );  
bufferOut[i] += len - 1;  
\*bufferOut[i] = 0; // ~= chomp  
bufferOut[i] -= len - 1;  
i++;  
}  
bufferOut[i] = NULL;  
}  
}  
}

C ext to Ruby side:  
±----------------+

VALUE ary = rb\_ary\_new2( LINES\_MAX );  
i = 0;  
while( bufferOut[i] != NULL)  
{  
rb\_ary\_push( ary, (VALUE) rb\_str\_new2( bufferOut[i] ) );  
i++;  
}

return ary;

obviously, it works but i’m not satisfied of the returned result  
because the user gets an array of it’s whole at a time, where i would  
prefer continously outputting the values (string in this case)

then i wonder if there is a way somehow to return the  
“myCommunicationsPipe” above directly (more directly) from C to ruby.

something like IO.popen…

BUT, i’ve tried IO.popen in my RubyCocoa app it doesn’t work as  
expected, i get the whole result at a time intead of having the  
results in a line by nline basis…

some light about that ?
