I have a Perl script that uses an external tool (cleartool) to collect information about a list of files. I want to use IPC to avoid a new process for each file:
use IPC::Open2; my ($cin, $cout); my $child = open2($cout, $cin, 'cleartool');
Commands that return single-line lines work well. eg.
print $cin "describe -short $file\n"; my $description = <$cout>;
Commands that return multiple lines make me stump for how to use the whole answer without focusing on the lock:
print $cin "lshistory $file\n";
I tried to set the file descriptor for non-blocking reads via fcntl :
use Fcntl; my $flags = ''; fcntl($cout, F_GETFL, $flags); $flags |= O_NONBLOCK; fcntl($cout, F_SETFL, $flags);
but Fcntl dies with the message "Your provider has not defined the Fcntl macro F_GETFL."
I tried to use IO :: Handle to set $cout->blocking(0) , but that fails (it returns undef and sets $! "Unknown error").
I tried using select to determine if data is available before trying to read:
my $rfd = ''; vec($rfd, fileno($cout), 1) = 1; while (select($rfd, undef, undef, 0) >= 0) { my $n = read($cout, $buffer, 1024); print "Read $n bytes\n";
but it hangs without even reading anything. Does anyone know how to make this work (on Windows)?
windows perl ipc
Michael carman
source share