On 8/7/07, vishnu <[EMAIL PROTECTED]> wrote:
> This is my main file (5.8 version)
>
> my $pid = open( WRITE, "| ./sample.pl arglist" );
> WRITE->autoflush(1);
> print $pid,"\n";
> waitpid( $pid,0 );
>
> this is my child process:(sample.pl )
> #!/usr/bin/perl -w
> my @arg = @ARGV;
> my $length = @ARGV;
> print "...................... @arg\n";
> print "Child Pid $$ just read this \n";
>
> Now is there anyway read childs output in parent.... so that i can have the
> return values in a variable...
snip
This works for me. It also avoids most of the VMWare cruft by
directly using the "right" Perl interpretor.
[EMAIL PROTECTED]:~$ cat master.pl
#!/usr/bin/perl
use strict;
use warnings;
use IPC::Open2;
$SIG{PIPE} = sub { die "something broke\n" };
my $pid = open2 my $in, my $out, "./vmware.pl";
print "startup:\n";
while (<$in>) {
print "\t$_";
last if /$pid: end of message/;
}
print $out "run xyz\n";
print "xyz's output:\n";
while (<$in>) {
print "\t$_";
last if /$pid: end of message/;
}
print $out "quit\n";
print "quit's output:\n";
print "xyz's output:\n";
while (<$in>) {
print "\t$_";
last if /$pid: end of message/;
}
[EMAIL PROTECTED]:~$ cat vmware.pl
#!/usr/lib/vmware-server/perl5/bin/perl -w
BEGIN { push @INC, "/usr/lib/vmware-server/perl5/site_perl/5.005" }
use strict;
print "running $]\n";
print "$$: end of message\n";
$| = 1;
my %dispatch = (
xyz => \&xyz,
foo => \&foo,
bar => \&bar
);
while (<>) {
if (/^quit$/) {
print "shutting down\n";
last;
}
unless (/^run (.*)$/) {
print "unknown command: $_";
print "$$: end of message\n";
next;
}
my $task = $1;
if ($dispatch{$task}) {
$dispatch{$task}->();
} else {
print "unknown task: $task\n";
print "$$: end of message\n";
}
}
print "$$: end of message\n";
sub xyz {
print "ran xyz\n";
print "$$: end of message\n";
}
sub foo {
print "ran foo\n";
print "$$: end of message\n";
}
sub bar {
print "ran bar\n";
print "$$: end of message\n";
}
[EMAIL PROTECTED]:~$ ./master.pl
startup:
running 5.00503
12798: end of message
xyz's output:
ran xyz
12798: end of message
quit's output:
xyz's output:
shutting down
12798: end of message
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/