Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] How to pass a file hanlde to Child process

Expand Messages
  • Chaofei Yang
    hi. actually i ve found how to do that. open(INPUT,
    Message 1 of 3 , Apr 11, 2009
    • 0 Attachment
      hi.
      actually i've found how to do that.

      open(INPUT, "< /etc/motd") or die "/etc/motd: $!";
      if ($pid = fork) { wait }
      else {
      defined($pid) or die "fork:$!";
      open(STDIN, "<&INPUT") or die "dup: $!";
      exec("cat", "-n") or die "exec cat: $!";#or system(...);
      }but now.i just want to pass a file handle into a parallel process.and how to pass a socket to a new process.
      <unix networking programing v1> 2edition  there is some detials about what i want in 14.7 in that book.
      another way to do that is like this.
      but i can't create a file handle with a file descriptor.it doesn't work in the new process in windows.
      if (defined($ENV{input_fdno}) && $ENV{input_fdno}) =~ /^\d$/) {
              open(INPUT, "<&=$ENV{input_fdno}")
              or die "can't fdopen $ENV{input_fdno} for input: $!";
      }


      ________________________________
      From: Jeff Soules <soules@...>
      To: perl-beginner@yahoogroups.com
      Sent: Sunday, April 12, 2009 12:00:46 AM
      Subject: Re: [PBML] How to pass a file hanlde to Child process





      Hi there,

      This does not answer the original question and may be naive, but why
      not just have the child process [re]open the file? Is there a reason
      you need to use the existing file handle, instead of creating a new
      one within the child?

      On Fri, Apr 10, 2009 at 9:23 PM, q11112345 <q11112345@yahoo. com> wrote:
      >
      >
      > i want to pass a file handle to child process.like this:
      > system("perl child.pl $filehandle" );
      > but it doesn't work.the value passed to child is only a string.i can't use
      > it to read file.
      >
      > if i pass it like this:
      > $LB::var;
      > i can't use it in child process either.
      >
      > like this:
      > %ENV{$var}=$ filehanlde;
      > it doesn't work.it is also a string value can't be used as a file handle.
      >
      > or like this:
      > open (TEXT,"file" );
      > system("perl child.pl",*TEXT) ;
      > in child i use the parameter like this:
      > local *TEXT=shift;
      > while(<TEXT> ){
      > print;
      > }
      > it doesn't work either.
      >
      > maybe i can't pass a variable in command line like
      > system("perl child.pl" ,parameter);
      > maybe i can't create a child process like this..
      >
      > how could i pass a file handle to child process when using system to create
      > child process.
      > should i create child process in other way. then i can pass the file handle.
      >
      >






      [Non-text portions of this message have been removed]
    Your message has been successfully submitted and would be delivered to recipients shortly.