On 25 Jun, 03:43, [EMAIL PROTECTED] (Zentara) wrote: > On Tue, 24 Jun 2008 16:44:47 -0700 (PDT), [EMAIL PROTECTED] (shorti) > wrote: > > >Hello, I am a C coder but new to Perl. I am running in an AIX > >environment. I was wondering if there was a Perl way to return string > >data (or larger int values) to a C program? For instance, if I use > >the command : > > >ps aux | grep process123 my out put would look like this: > > >emextra 45304 0.0 0.0 7344 6120 - A 20:08:01 0:00 > >process123 > >I want to retrieve the 2nd and 5th columns of the output. I *think* I > >can figure out a way for Perl to get these columns but is there a way > >to return these values to my C program? > > >Any advise would be appreciated > > Use IPC::Open3 and do what is needed. You can get the output, > regex it, and feed the results back to the C program, IIUYC. > > #!/usr/bin/perl > use warnings; > use strict; > use IPC::Open3; > > #interface to "bc" calculator > #my $pid = open3(\*WRITE, \*READ, \*ERROR,"bc"); > my $pid = open3(\*WRITE, \*READ,0,"bc"); > #if \*ERROR is false, STDERR is sent to STDOUT > while(1){ > print "Enter expression for bc, i.e. 2 + 2\n"; > chomp(my $query = <STDIN>); > > #send query to bc > print WRITE "$query\n"; > > #give bc time to output > select(undef,undef,undef,.5); > > #get the answer from bc > chomp(my $answer = <READ>); > print "$query = $answer\n"; > > } > > waitpid($pid, 1); > # It is important to waitpid on your child process, > # otherwise zombies could be created. > __END__ > > -- > I'm not really a human, but I play one on > earth.http://zentara.net/CandyGram_for_Mongo.html
Forgive me, Zentara, but this doesnt appear to show how to feed the results back to C. It would seem that I would have to run the script via a system() call. I still am not sure how to get the $answer info back to the C program. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/