Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Queries on open3

by ikegami (Patriarch)
on Apr 22, 2009 at 19:48 UTC ( #759389=note: print w/replies, xml ) Need Help??


in reply to Queries on open3

Some notes before I get started:

  • Could you remove your <pre>..</pre> tags please? Use <p> at the start of paragraphs. Use <c>..</c> or <code>..</code> around computer text, code and data..

  • You seem to be reinventing parts of IPC::Run. Is there really a need for this module?

I have couple of problems in dealing with Filehandlers

They are called "file handles". Note the space and the lack of "r".

Want to check whether input filehandler is ready to receive input

can_write and select in IO::Select will tell you that on non-Windows systems. I don't think it's possible in Windows. (Alternate paradigms are used.)

Issues with output and error filehandlers in returning buffer text

Sorry, but you can't control whether another process buffers its output or not unless the specific program provides you a specific means (e.g. a command line option) of doing so.

However, you can fool most by creating a pseudo-tty. See IPC::Run and IO::Pty.

Filehandle GEN0 opened only for output at Task.pm line 89.

You should have two selectors. One for inputs and one for outputs.

sub DESTROY { my $self = shift; &stop; }

That should be

sub DESTROY { my $self = shift; $self->stop(); }

stop expects to be called as a method.

local $SIG{INT} = 'IGNORE'; kill INT => -$$;

That should be

kill INT => $self->{pid};

There's no reason to kill every child.

Replies are listed 'Best First'.
Re^2: Queries on open3
by thiagu_mvt (Sexton) on Apr 23, 2009 at 14:03 UTC

    When I change my function as below and send "sleep 50" as a command, can_write is returning input file handle as one of the value. so it means it can be written ?. I expected it should not return input file handle since we cannot write into 'sleep' command.

    Any Explanation or fix??

    sub canSendInput { my $self = shift; my $pid = waitpid($self->{pid}, WNOHANG) my @ready = $self->{'selector'}->can_write(1);# Dumper(\@ready); }

    Thanks,
    Thiagu

      I expected it should not return input file handle since we cannot write into 'sleep' command.

      You don't write "into a sleep command". You write into a pipe. As long as the pipe isn't full, it'll report that it can accept data.

      Perhaps you want Expect?

        I have used syswrite and checking the number of bytes written. also using SIGPIPE.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://759389]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2022-08-08 17:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?