It will be asynchronous in the sense that the command output can be read while it is being executed (as a child process). Otherwise it is synchronous in the sense that you can't move outside the scope of the filehandle $xx without explicitly killing the child.
This is the normal usage based on "Perl Cookbook"'s "16.4. Reading or Writing to Another Program" (edit: sorry for pirated link! I did not know, thanks Fletch)
my $pid = open(my $xx, "od -w1 -v -An -N5 -td1 < /dev/random 2>&1|")
or die "fork: $!";
if( $pid ){
while(<$xx>){
print "read: $_";
}
}
close($xx) or die "command failed with ".($?>>8);
The following code demonstrates what I mean by "outside the scope of the filehandle". At the goto it waits for the spawned command to be finished:
{
my $pid = open(my $xx, "sleep 10|")
or die "fork: $!";
if( $pid ){
goto XX;
while(<$xx>){
print "read: $_";
}
}
close($xx) or die "command failed with ".($?>>8);
}
XX:
print "here\n";
You will notice that "here" is printed only upon script exit. Whereas, the following executes the goto because it is within scope but script does not exit until sleep exits. Perhaps half-asynchronously would be a better term ;)
my $pid = open(my $xx, "sleep 10|")
or die "fork: $!";
if( $pid ){
goto XX;
while(<$xx>){
print "read: $_";
}
}
close($xx) or die "command failed with ".($?>>8);
XX:
print "here\n";
"here" is printed at the goto, then there is implicit waiting for sleep to end.
bw, bliako |