+ -
当前位置:首页 → 问答吧 → POE::Wheel::Run::Win32模块,参数不能传递

POE::Wheel::Run::Win32模块,参数不能传递

时间:2010-09-08

来源:互联网

发现POE::Wheel::Run::Win32有一个问题··不知道是模块的问题··还是我代码有问题,
有参数就不能运行test.pl,没参数可以~~·不知道什么问题~~百思不得其解~~~望指教~~
先上代码,代码如下:(和模块自带的例子一样··就是Program 那里改了一下)
  1. use warnings;
  2.   use strict;

  3.   use POE qw( Wheel::Run::Win32 );

  4.   POE::Session->create(
  5.     inline_states => {
  6.       _start           => \&on_start,
  7.       got_child_stdout => \&on_child_stdout,
  8.       got_child_stderr => \&on_child_stderr,
  9.       got_child_close  => \&on_child_close,
  10.       got_child_signal => \&on_child_signal,
  11.     }
  12.   );

  13.   POE::Kernel->run();
  14.   exit 0;

  15.   sub on_start {
  16.     my $child = POE::Wheel::Run::Win32->new(
  17.       Program => sub{exec('test.pl','2.txt');},#有后面那个‘2.txt’就不行···程序会出错,没有参数的话··可以运行
  18. #    Program => 'test.pl',#不行
  19.       StdoutEvent  => "got_child_stdout",
  20.       StderrEvent  => "got_child_stderr",
  21.       CloseEvent   => "got_child_close",
  22.     );

  23.     $_[KERNEL]->sig_child($child->PID, "got_child_signal");

  24.     # Wheel events include the wheel's ID.
  25.     $_[HEAP]{children_by_wid}{$child->ID} = $child;

  26.     # Signal events include the process ID.
  27.     $_[HEAP]{children_by_pid}{$child->PID} = $child;

  28.     print(
  29.       "Child pid ", $child->PID,
  30.       " started as wheel ", $child->ID, ".\n"
  31.     );
  32.   }

  33. sub run
  34. {
  35.         exec 'D:\\test-area\\remote\\test.pl';
  36. }
  37.   # Wheel event, including the wheel's ID.
  38.   sub on_child_stdout {
  39.     my ($stdout_line, $wheel_id) = @_[ARG0, ARG1];
  40.     my $child = $_[HEAP]{children_by_wid}{$wheel_id};
  41.     print "pid ", $child->PID, " STDOUT: $stdout_line\n";
  42.   }

  43.   # Wheel event, including the wheel's ID.
  44.   sub on_child_stderr {
  45.     my ($stderr_line, $wheel_id) = @_[ARG0, ARG1];
  46.     my $child = $_[HEAP]{children_by_wid}{$wheel_id};
  47.     print "pid ", $child->PID, " STDERR: $stderr_line\n";
  48.   }

  49.   # Wheel event, including the wheel's ID.
  50.   sub on_child_close {
  51.     my $wheel_id = $_[ARG0];
  52.     my $child = delete $_[HEAP]{children_by_wid}{$wheel_id};

  53.     # May have been reaped by on_child_signal().
  54.     unless (defined $child) {
  55.       print "wid $wheel_id closed all pipes.\n";
  56.       return;
  57.     }

  58.     print "pid ", $child->PID, " closed all pipes.\n";
  59.     delete $_[HEAP]{children_by_pid}{$child->PID};
  60.   }

  61.   sub on_child_signal {
  62.     print "pid $_[ARG1] exited with status $_[ARG2].\n";
  63.     my $child = delete $_[HEAP]{children_by_pid}{$_[ARG1]};

  64.     # May have been reaped by on_child_close().
  65.     return unless defined $child;

  66.     delete $_[HEAP]{children_by_wid}{$child->ID};
  67.   }
复制代码
test.pl的代码如下:
  1. use strict;
  2. my $file = shift @ARGV;
  3. #my $file ='1.txt';
  4. my $str = 'the return values';
  5. print $str,"\n";
  6. open F,">",$file;
  7. print F $str,"\n";
  8. close F;
复制代码

作者: wfnh   发布时间: 2010-09-08

顶上

作者: wfnh   发布时间: 2010-09-08