Discussion:
popen output
Valnir
2008-04-12 13:39:15 UTC
Permalink
Hey guys.. hopefully someone still watches this list.. I need to be able to
read the output from a popen pipe. Can someone tell me how? Thanks!

Valnir
Head Coder
Legend of the Nobles
-----------------------------------
***@legendofthenobles.com
http://www.legendofthenobles.com
telnet://play.legendofthenobles.com:5400
--
ROM mailing list
***@rom.org
Unsubscribe here ->>> http://www.rom.org/cgi-bin/mailman/listinfo/rom
BluSky
2008-04-13 12:59:46 UTC
Permalink
Wow, it's been almost a year since I've seen anything on the list.

Sorry, though. I don't know the answer.

|\ _,,,---,,_
/,`.-'`' -. ;-;;,_
|,4- ) )-,_..;\ ( `'-'
'---''(_/--' `-'\_)
BluSky is often lurking at Afterlife MUD:
***@eskimo.com * http://www.afterlife-mud.org
------------------> telnet://afterlife-mud.org:7777
ROM FAQ ----------> http://www.hypercube.org/tess/rom/
ROMList Archive --> http://www.the-infinite.org/lists/romlist/
----- Original Message -----
From: "Valnir" <***@legendofthenobles.com>
To: <***@rom.org>
Sent: Saturday, 12 April 2008 0639
Subject: popen output
Post by Valnir
Hey guys.. hopefully someone still watches this list.. I need to be able to
read the output from a popen pipe. Can someone tell me how? Thanks!
Valnir
Head Coder
Legend of the Nobles
-----------------------------------
http://www.legendofthenobles.com
telnet://play.legendofthenobles.com:5400
--
ROM mailing list
Unsubscribe here ->>> http://www.rom.org/cgi-bin/mailman/listinfo/rom
--
ROM mailing list
***@rom.org
Unsubscribe here ->>> http://www.rom.org/cgi-bin/mailman/listinfo/rom
Davion Kalhen
2008-04-13 17:39:53 UTC
Permalink
Post by Valnir
Hey guys.. hopefully someone still watches this list.. I need to be able to
read the output from a popen pipe. Can someone tell me how? Thanks!
Valnir
Head Coder
Legend of the Nobles
-----------------------------------
http://www.legendofthenobles.com
telnet://play.legendofthenobles.com:5400
--
ROM mailing list
Unsubscribe here ->>> http://www.rom.org/cgi-bin/mailman/listinfo/rom
popen returns a standard i/o stream so you just read from it exactly
like a file! Make sure when you invoke it you use 'r'. eg

#include <stdio.h>
int main( void )
{ FILE *pipe;
char c;
if( ! ( pipe = popen("ls -l", "r") ) )
{ perror("ls -l");
return;
}

while( ( c = fgetc(pipe) ) != EOF )
printf("%c", c);
return 0;
}


Davion
--
A MudBytes Administrator
http://www.mudbytes.net - A Code Repository
--
ROM mailing list
***@rom.org
Unsubscribe here ->>> http://www.rom.org/cgi-bin/mailman/listinfo/rom
Valnir
2008-04-13 20:39:54 UTC
Permalink
Hey all... thanks for all your input. I also received some off-list
assistance from Dale yesterday and was able to come up with the answer. I
was trying to scan for duplicate email addresses in our user accounts and
here is the final function that is working perfectly.

bool check_dup_email ( DESCRIPTOR_DATA *d, char *email )
{
FILE *fp;
char buf[MSL], cmd[MIL];
bool duplicate = FALSE;

write_to_buffer( d, "Please wait while we scan for duplicate
accounts....\n\r", 0 );
sprintf( cmd, "grep -i '%s' %s*.usr\n", email, USER_DIR );

if ( ( fp = popen( cmd, "r" ) ) == NULL )
{
bug( "check_dup_email: Error opening shell!", 0 );
return FALSE;
}
else
{
fgets( buf, sizeof(buf), fp );

if ( strstr( buf, ".usr" ) )
{
sprintf( buf, "Attempt to use duplicate email address (%s)
detected.", email );
log_string( buf );
duplicate = TRUE;
}

pclose( fp );
}

return (duplicate);
}

- Valnir


-----Original Message-----
From: ***@gmail.com [mailto:***@gmail.com] On Behalf Of Michael
Barton
Sent: Sunday, April 13, 2008 12:30 PM
To: Nathan Kodak
Cc: ***@rom.org
Subject: Re: popen output

It's basically like reading from any other file.
So you can do something like:

FILE *fp = popen("/bin/ls -l", "r");
char line[1024];

while (fgets(line, sizeof(line), fp))
{
printf("line: %s", line);
}
Post by Valnir
Hey guys.. hopefully someone still watches this list.. I need to be able to
read the output from a popen pipe. Can someone tell me how? Thanks!
Valnir
Head Coder
Legend of the Nobles
-----------------------------------
http://www.legendofthenobles.com
telnet://play.legendofthenobles.com:5400
--
ROM mailing list
Unsubscribe here ->>> http://www.rom.org/cgi-bin/mailman/listinfo/rom
--
ROM mailing list
***@rom.org
Unsubscribe here ->>> http://www.rom.org/cgi-bin/mailman/listinfo/rom
rabidcoconut
2008-04-14 22:35:17 UTC
Permalink
Not a clue, but it's nice to see something on this list, thought it was
dead.

-----Original Message-----
From: rom-***@rom.org [mailto:rom-***@rom.org] On Behalf Of Valnir
Sent: Saturday, April 12, 2008 6:39 AM
To: ***@rom.org
Subject: popen output

Hey guys.. hopefully someone still watches this list.. I need to be able to
read the output from a popen pipe. Can someone tell me how? Thanks!

Valnir
Head Coder
Legend of the Nobles
-----------------------------------
***@legendofthenobles.com
http://www.legendofthenobles.com
telnet://play.legendofthenobles.com:5400
--
ROM mailing list
***@rom.org
Unsubscribe here ->>> http://www.rom.org/cgi-bin/mailman/listinfo/rom
--
ROM mailing list
***@rom.org
Unsubscribe here ->>> http://www.rom.org/cgi-bin/mailman/listinfo/rom
Loading...