U
usenet
Consider this little complete perl program, intended to imitate a
shell's
gcc -v -E -x c - </dev/null >/dev/null
command:
#!/usr/bin/env perl
use warnings;
use strict;
use File::Spec;
use IPC::Open3;
# WORKS: shell$ gcc -v -E -x c - </dev/null >/dev/null
# WORKS: my @cmd = ('gcc', '-v', '-E', '-x', 'c', '/dev/null');
# This one never gets out of the while loop.
my @cmd = ('gcc', '-v', '-E', '-x', 'c', '-');
if (open (my $NULLOUT, ">", File::Spec->devnull)) {
if (open (my $NULLIN, "<", File::Spec->devnull)) {
my $pid = open3 ($NULLIN, $NULLOUT, \*CMD, @cmd);
while (<CMD>) {
print;
}
print "left while(<CMD>)\n";
waitpid ($pid, 0);
close CMD;
close $NULLIN;
}
close $NULLOUT;
}
I wonder why it never gets out of the "while" loop, but apparently
hangs somewhere waiting to read input that never arrives (after
printing gcc's stderr correctly). ps(1) says its wait channel it
piperd,
$ ps -o wchan,args|grep perl
piperd perl ./o3.pl (perl5.8.8)
I'm stumped. Does any perl guru know what's going on and how to
correct the situation?
Regards, Jens
shell's
gcc -v -E -x c - </dev/null >/dev/null
command:
#!/usr/bin/env perl
use warnings;
use strict;
use File::Spec;
use IPC::Open3;
# WORKS: shell$ gcc -v -E -x c - </dev/null >/dev/null
# WORKS: my @cmd = ('gcc', '-v', '-E', '-x', 'c', '/dev/null');
# This one never gets out of the while loop.
my @cmd = ('gcc', '-v', '-E', '-x', 'c', '-');
if (open (my $NULLOUT, ">", File::Spec->devnull)) {
if (open (my $NULLIN, "<", File::Spec->devnull)) {
my $pid = open3 ($NULLIN, $NULLOUT, \*CMD, @cmd);
while (<CMD>) {
print;
}
print "left while(<CMD>)\n";
waitpid ($pid, 0);
close CMD;
close $NULLIN;
}
close $NULLOUT;
}
I wonder why it never gets out of the "while" loop, but apparently
hangs somewhere waiting to read input that never arrives (after
printing gcc's stderr correctly). ps(1) says its wait channel it
piperd,
$ ps -o wchan,args|grep perl
piperd perl ./o3.pl (perl5.8.8)
I'm stumped. Does any perl guru know what's going on and how to
correct the situation?
Regards, Jens