Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Reading progress of "copy" executed asynchronously

by bliako (Monsignor)
on Aug 08, 2018 at 21:59 UTC ( [id://1220132]=note: print w/replies, xml ) Need Help??


in reply to Reading progress of "copy" executed asynchronously

Fork a child to filestat (unix stat is required or windows equivalent) while parent copies on...:

#!/usr/bin/env perl use strict; use warnings; # assumes file src is 'aaa' and dest is 'bbb' my $cmd1 = 'cp'; # path to OS filecopy command my @args1 = ('aaa', 'bbb'); my $cmd2 = 'stat'; # path to OS file-stat command my @args2 = qw/-c '%s' bbb/; # unix stat params to print size of targe +t file 'bbb' my $pid = fork(); die "fork! $!" if not defined $pid; if( $pid > 0 ){ # child my $keepon = 1; $SIG{TERM} = sub { $keepon = 0; print "sigterm received\n"; }; sleep 2; # let the copy begin first ... while($keepon){ open(EXE2, '-|', $cmd2, @args2) or die "$!"; my $sta = ''; while(<EXE2>){ $sta .= $_ } print "$0 : file size now is $sta\n"; close(EXE2); sleep 1; } print "child out of loop and dead...\n"; } else { # parent print "$0 : starting copy ...\n"; system($cmd1, @args1) == 0 or die "system failed $cmd1, $!"; print "parent exiting\n"; kill -15, $pid; # kill the child :( }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1220132]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-04-19 02:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found