Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re^4: why IPC::Open3 can't execute MS-DOS "dir" command?

by ikegami (Pope)
on Dec 07, 2009 at 23:56 UTC ( #811650=note: print w/replies, xml ) Need Help??

in reply to Re^3: why IPC::Open3 can't execute MS-DOS "dir" command?
in thread why IPC::Open3 can't execute MS-DOS "dir" command?

use strict; use warnings; use IO::Select qw( ); use IPC::Open3 qw( open3 ); use Socket qw( AF_UNIX SOCK_STREAM PF_UNSPEC ); sub _pipe { socketpair($_[0], $_[1], AF_UNIX, SOCK_STREAM, PF_UNSPEC) or return undef; shutdown($_[0], 1); # No more writing for reader shutdown($_[1], 0); # No more reading for writer return 1; } sub _open3 { local (*TO_CHLD_R, *TO_CHLD_W); local (*FR_CHLD_R, *FR_CHLD_W); local (*FR_CHLD_ERR_R, *FR_CHLD_ERR_W); if ($^O =~ /Win32/) { _pipe(*TO_CHLD_R, *TO_CHLD_W ) or die $^E; _pipe(*FR_CHLD_R, *FR_CHLD_W ) or die $^E; _pipe(*FR_CHLD_ERR_R, *FR_CHLD_ERR_W) or die $^E; } else { pipe(*TO_CHLD_R, *TO_CHLD_W ) or die $!; pipe(*FR_CHLD_R, *FR_CHLD_W ) or die $!; pipe(*FR_CHLD_ERR_R, *FR_CHLD_ERR_W) or die $!; } my $pid = open3('>&TO_CHLD_R', '<&FR_CHLD_W', '<&FR_CHLD_ERR_W', @ +_); return ( $pid, *TO_CHLD_W, *FR_CHLD_R, *FR_CHLD_ERR_R ); } my ($pid, $to_chld, $fr_chld, $fr_chld_err) = _open3('cmd /c "dir /s/b"'); my %objs; my $in_sel = IO::Select->new(); my $out_sel = IO::Select->new(); for my $fh ($fr_chld, $fr_chld_err) { my $obj = { buf => '', }; $objs{ fileno($fh) } = $obj; $in_sel->add($fh); } close($to_chld); while ($in_sel->count() + $out_sel->count()) { my ($ins, $outs) = IO::Select::select($in_sel, $out_sel, undef); for my $fh (@$ins) { my $obj = $objs{ fileno($fh) }; our $buf; local *buf = \( $obj->{buf} ); my $bytes_read = sysread($fh, $buf, 64*1024, length($buf)); if (!$bytes_read) { warn("Error reading from child: $!\n") if !defined($bytes_read); $in_sel->remove($fh); } } for my $fh (@$outs) { } } waitpid($pid, 0); print("STDOUT:\n$objs{ fileno( $fr_chld ) }{buf}"); print("\n"; print("STDERR:\n$objs{ fileno( $fr_chld_err ) }{buf}");

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://811650]
[choroba]: Algorithm::Loops
[Corion]: choroba: I'm using that to generate the permutations, but I don't know how the user can pass the intended values to my function in a sane way
[Corion]: I have a prototype that permutes the get_parameters, but the values used for the get parameters should be different from the values used for the headers and potentially for parts of the URL
[Corion]: But yes, in general, my approach will be "split the URL into another set of parameters, generate an array of allowed values for each parameter and then NestedLoops() over the set"
[choroba]: hmm... so you need something like bag from Test::Deep, but not for checking, but for generation
[Corion]: This has the dual use of easily requesting sequential URLs and also being suitable for testing
[Corion]: For testing, I want to skip all tests with the same value(s) once one test fails to cut down on the number of failing tests
[Corion]: choroba: Yes, in a way I
[Corion]: ... I'm treating the incoming value sets as bags... Maybe I'll just put the burden on the user, at least in the first attempt at a full API. generate( headers => [{ 'Content-Type' => 'text/plain' }, {'Content-Type' => 'text/json' ] ), even ...
[Corion]: ... if that is cumbersome for the caller to specify. On the other hand, maybe there isn't that big a need for permuting the header values

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2017-01-17 08:22 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (152 votes). Check out past polls.