[Chicago-talk] trouble caputuring return value
Richard Reina
richard at rushlogistics.com
Wed Mar 31 10:01:27 PDT 2010
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
>
More information about the Chicago-talk
mailing list