in reply to How to pass the value of a variable from a child to parent with gui interface?
or what I might be doing terribly wrong?
Processes do not share variables. Once you fork(), each process has its own copy of the variables, and any changes to the variables are local to the process. The subject you need to research is IPC (inter process communication). You might start by reading perlipc.
Here is an example of what you can do:
Note the consequences to the parent, which is not something you want to do in a gui setting. The gui environments I'm familiar with--perl not being one of them--usually have a special setup for executing long running processes, which automatically signal the gui when they are done. You can then set up a listener for that 'event' and do something in response.use strict; use warnings; use 5.010; my @lines = qw{ LINE1 LINE2 LINE3 LINE4 LINE5 }; my $pid = open my $INPUT_FROM_CHILD, '-|'; if (!defined $pid) { die "Couldn't fork: $!"; } if ($pid) { say 'parent: blocking until child sends some data...'; while (<$INPUT_FROM_CHILD>) { #line oriented reading chomp; say "parent: $_"; } waitpid($pid, 0); say "parent: child exited with status = $?"; say 'parent: exiting...'; } else { sleep 2; say $lines[int(rand(@lines))]; close $INPUT_FROM_CHILD; sleep 10; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to pass the value of a variable from a child to parent with gui interface?
by BrowserUk (Patriarch) on Mar 13, 2010 at 04:38 UTC | |
by ikegami (Patriarch) on Mar 13, 2010 at 04:47 UTC | |
by BrowserUk (Patriarch) on Mar 13, 2010 at 04:49 UTC | |
by Anonymous Monk on Mar 13, 2010 at 10:16 UTC | |
| |
|
Re^2: How to pass the value of a variable from a child to parent with gui interface?
by ZJ.Mike.2009 (Scribe) on Mar 13, 2010 at 04:39 UTC |