I'm trying to make a script that communicates with mplayer using open3, but the mplayer process is showing up as defunct and I am unable to send standard input into mplayer.
Here's the code:
#!/usr/bin/env perl
{
package mplayer::test;
use IPC::Open3;
sub new {
my $class = shift;
my $self = bless { @_ }, $class;
$self->start_mplayer();
$self;
}
sub start_mplayer{
my $self = shift;
local *DEVNULL;
open DEVNULL, ">/dev/null" or die "/dev/null: $!";
open OUTPUT, ">out.log" or die "out.log: $!";
$self->{r} = local *MPLAYER_READ;
$self->{w} = local *MPLAYER_WRITE;
$self->{pid} = open3($self->{w},$self->{r},">&DEVNULL",'mplayer -slave -idle -v');
die "Error opening mplayer!\n" unless $self->{pid};
}
sub do{
my ($self, $command) = @_;
print {$self->{w}} $command, "\n";
}
}
mplayer::test->new;
mplayer::test->do(qq~loadfile test.mp3~);
sleep(5);
I must be missing something obvious, I'm learning open3 from examples from other modules.