[Chicago-talk] Chicago-talk Digest, Vol 80, Issue 27

Brad Doty bdoty at eqtc.com
Wed Mar 31 12:32:10 PDT 2010


Hold the phone.  Why are you guys making this evermore complicated?
Good God, you don't need sockets to shell out to the system!  

And you don't need to start reading Unix books on IPC to do this task.

First of all, Richard, what do you want to do?

Is there a reason this has to be a separate Perl process in a separate
gnome-window?

If not, you could write a simple Perl program to call the get_input
function and then call that from a shell script that opens a gnome
window.  You'd have nothing interprocess going on in Perl.

Assuming you have an existing Perl process that needs to open a separate
window for this input...

I would suggest starting with the ole reliable open pipe function.

I'm not familiar with perl on the fly with -e, but what's wrong with
something like?

open (INPUT, "gnome-terminal --geometry=80x12-0-30 -x perl -e 'require
> > "./get_info.pl"; my $input = get_input(); print $input' |");
while (<INPUT>)
{ my $info = $_;  # or whatever processing you need }

OR if you just want to print out the lines generated by get_input()...
my @info = <INPUT>;   ## Assigns all lines from INPUT to @info
print @info;


Call me old-fashioned, but I'd write a Perl script that opens the
gnome-terminal and prints the output of get_input on stdout and call
that with

open (INPUT, "readInput.pl |");
while (<INPUT>)
{  process the input }

Maybe I'm missing something, but Perl makes shelling out to the system,
even to a new window very easy if you let it.

-  
Thanks,

Brad


-----Original Message-----
From: chicago-talk-request at pm.org
Reply-to: chicago-talk at pm.org
To: chicago-talk at pm.org
Subject: Chicago-talk Digest, Vol 80, Issue 27
Date: Wed, 31 Mar 2010 12:00:08 -0700

Send Chicago-talk mailing list submissions to
	chicago-talk at pm.org

To subscribe or unsubscribe via the World Wide Web, visit
	http://mail.pm.org/mailman/listinfo/chicago-talk
or, via email, send a message with subject or body 'help' to
	chicago-talk-request at pm.org

You can reach the person managing the list at
	chicago-talk-owner at pm.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Chicago-talk digest..."


Today's Topics:

   1. Last day for YAPC::NA talk submissions... (Joshua)
   2. Re: trouble caputuring return value (Richard Reina)
   3. Re: trouble caputuring return value (Ted Zlatanov)


----------------------------------------------------------------------

Message: 1
Date: Wed, 31 Mar 2010 08:13:35 -0600
From: Joshua <joshua.mcadams at gmail.com>
Subject: [Chicago-talk] Last day for YAPC::NA talk submissions...
To: "Chicago.pm chatter" <chicago-talk at pm.org>
Message-ID:
	<g2q49d805d71003310713s5947f708sbccb8df01c2a0e6c at mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

http://conferences.mongueurs.net/yn2010/newtalk


------------------------------

Message: 2
Date: Wed, 31 Mar 2010 13:01:27 -0400 (EDT)
From: Richard Reina <richard at rushlogistics.com>
Subject: Re: [Chicago-talk] trouble caputuring return value
To: "Chicago.pm chatter" <chicago-talk at pm.org>
Message-ID: <20100331170128.11B2D3563 at theseus.xo.com>
Content-Type: text/plain; charset="utf-8"

Shlomi,

Thanks for your reply. Is this something complicated to do?  If it is I just opt to save the input to a file and have the 1st program open the file to get it.  I was just wondering if you had an idea how steep of a learning curve I have in front of me.

Thanks,

Richard


---- Chicago.pm chatter <chicago-talk at pm.org> wrote:
>
> Hi Richard!
> 
> On Wednesday 31 Mar 2010 15:37:16 Richard Reina wrote:
> > I have a program that opens a separate terminal and prompts the user for
> > some information.  However, for some reason I can't seem to capture the
> > return value.  Does anyone happen to know why the value returned by
> > get_info.pl is not getting returned? Any help would really be appreciated.
> > 
> > Thanks
> > Richard
> > 
> > #!/usr/bin/perl -w
> > 
> > use strict;
> > my $info;
> > 
> > system(q{gnome-terminal --geometry=80x12-0-30 -x perl -e 'require
> > "./get_info.pl"; ($info) = get_input();'});
> 
> You should not expect Perl to assign to a variable in the main program by 
> evaluating an assignment to its name in a different process. To communicate 
> with a child process you need inter-process communications, such as anonymous 
> pipes, sockets, named pipes, System V IPC, mmap, using the file-system for 
> that, etc. Please read a little about UNIX multi-processing basics (a lot of 
> which is also relevant to Windows and other operating systems). 
> 
> > print $info . "\n";
> > 
> > 
> > <<<<<<< get_info.pl >>>>>>>>
> > #!/usr/bin/perl -w
> > 
> > use strict;
> > 
> > print "Enter Info\n";
> > chomp (my $info = <STDIN>);
> > 
> > return $info;
> 
> You cannot use return to return an arbitrary Perl value from a program. It 
> only works for functions. As far as C and UNIX are concerned, everything that 
> comes out of a process must be in sequences of octets. You need to use 
> "print()" on something to emit it to the outside somehow.
> 
> Regards,
> 
> 	Shlomi Fish
> 
> -- 
> -----------------------------------------------------------------
> Shlomi Fish       http://www.shlomifish.org/
> What does "Zionism" mean? - http://shlom.in/def-zionism
> 
> Deletionists delete Wikipedia articles that they consider lame.
> Chuck Norris deletes deletionists whom he considers lame.
> 
> Please reply to list if it's a mailing list post - http://shlom.in/reply .
> _______________________________________________
> Chicago-talk mailing list
> Chicago-talk at pm.org
> http://mail.pm.org/mailman/listinfo/chicago-talk
> 


------------------------------

Message: 3
Date: Wed, 31 Mar 2010 12:03:17 -0500
From: Ted Zlatanov <tzz at lifelogs.com>
Subject: Re: [Chicago-talk] trouble caputuring return value
To: Chicago.pm chatter <chicago-talk at pm.org>
Cc: Richard Reina <richard at rushlogistics.com>
Message-ID: <87634cbezu.fsf at lifelogs.com>
Content-Type: text/plain; charset="us-ascii"

On Wed, 31 Mar 2010 16:13:27 +0300 Shlomi Fish <shlomif at iglu.org.il> wrote: 

SF> You should not expect Perl to assign to a variable in the main program by 
SF> evaluating an assignment to its name in a different process. To communicate 
SF> with a child process you need inter-process communications, such as anonymous 
SF> pipes, sockets, named pipes, System V IPC, mmap, using the file-system for 
SF> that, etc. Please read a little about UNIX multi-processing basics (a lot of 
SF> which is also relevant to Windows and other operating systems). 
...
SF> You cannot use return to return an arbitrary Perl value from a program. It 
SF> only works for functions. As far as C and UNIX are concerned, everything that 
SF> comes out of a process must be in sequences of octets. You need to use 
SF> "print()" on something to emit it to the outside somehow.

If shared memory is a possibility, Tie::ShareLite makes it *really* easy
to share information persistently between programs.

Richard could also look into wxWidgets, which would make the input
reader better and wouldn't depend on gnome-terminal.  If he explains
more about why he's splitting the task into a reader and a processor,
I'm sure he'd get more specific suggestions.

Ted


------------------------------

_______________________________________________
Chicago-talk mailing list
Chicago-talk at pm.org
http://mail.pm.org/mailman/listinfo/chicago-talk

End of Chicago-talk Digest, Vol 80, Issue 27
********************************************



More information about the Chicago-talk mailing list