thanks for the help and suggestions.
This feels like a race condition of some sort, but I can't see where it
might be. What does your script do next? Can you use ps to examine what
arguments actually get passed to the gmplayer-bin process? What happens
if you take the temporary file out of the equation and just supply a
literal string to mplayer? What happens if you use ordinary mplayer
rather than gmplayer-bin? Can you give us a minimal *complete* script
that reliably fails on your machine? Is there anything else different
between the two environments: different environment vars, different
shells, &c.? Does the program still succeed if you single-step in the
debugger (run it with perl -d) rather than using Emacs?
$video = $ARGV[0];
$vid_resume = vid_position_file($video);
if (-e $vid_resume) {
$pid = open2(*reader, *writer, "gmplayer-bin -slave -quiet -ss `cat $vid_resume` $video") || die "Unable to open $1: $!";
--> what follows:
unlink $vid_resume;
}
# else {
# $pid = open2(*reader, *writer, "gmplayer-bin -slave -quiet $video") || die "Unable to open $1: $!";
# }
# new position will be recorded here:
open(POS_FH, "> $vid_resume") || die "Unable to open $1: $!";
}
## otherwise bring up mplayer unloaded:
#else {
# $pid = open2(*reader, *writer, 'gmplayer-bin -slave -quiet') || die "Unable to open $1: $!";
#}
clear_mplayer();
.
.
.
sub clear_mplayer {
# ps'ing too fast is missing the "L" ("pages locked in memory"):
sleep 5;
my $video_pid = $pid; $video_pid++;
my $running = `/bin/ps ax`;
if ($running =~ /$video_pid\s+pts\/[0-9]+\s+(S|R)?L/) {
writer->autoflush();
while (! /Starting playback/) {
$_ = <reader>;
}
return 1;
}
else {
return 0;
}
}
-------------
1. once that sequence finishes the prog goes onto to other tasks and
everything from this point on works as expected
2. the rest of the if/else is only commented while I've been looking at
this problem (ensure either invocation uses the same one)
3. the problem isn't unlink - I ran with it commented and no change
4. I don't know what "writer->autoflush();" does but it was in the code I
lifted from a web page so left it in (in or out doesn't seem to impact
this -ss problem)
5. mplayer whether started with a vid arg or not appears to start with two
consecutive pids where the second indicates that a video is loaded or
running - to guarantee I can find mplayer's responses to my queries I
throw away everything up to "Starting..."; to guarantee I'll find
"Starting..." I don't look for it until the "L" in ps shows up.
-------------
wrt some of your easier suggestions:
- I tried plain mplayer, replacing cat with the pathname, added path to
g/mplayer bins and at best the video comes up running but ostensibly
ignoring -ss and at worst just comes up with video loaded but not
running.
- I ordinarily use csh but tried bash and sh, same behavior.
- I did notice a couple times in the past couple days that a specific
invocation repeated would seem to start ok (don't recall if it was using
-ss) and at other times came up with the video stopped; I thought "that
can't be, I must've not been paying attn to how I started it."
so there must be something to this race condition thing; I don't know
anything about the open2 alternative you mentioned but will see if I can
manage using that instead and see what happens.
--