Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^4: Reading progress of "copy" executed asynchronously

by neWerminder (Novice)
on Aug 10, 2018 at 08:26 UTC ( [id://1220181]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Reading progress of "copy" executed asynchronously
in thread Reading progress of "copy" executed asynchronously

Hello

As for code it wont work. i tried earlier on and it gives output only when its done but i need to monitor progress

As for IPC ill check

  • Comment on Re^4: Reading progress of "copy" executed asynchronously

Replies are listed 'Best First'.
Re^5: Reading progress of "copy" executed asynchronously
by vr (Curate) on Aug 10, 2018 at 12:48 UTC

    This works for me on Windows:

    use strict; use warnings; use feature 'say'; use POSIX ":sys_wait_h"; use Capture::Tiny ':all'; my $cmd = 'cmd /c copy a1GBfile a1GBfile_copy /z'; my $out = IO::File-> new_tmpfile; capture_stdout { my $pid = system( 1, $cmd ); while () { last if waitpid( $pid, WNOHANG ); undef local $/; seek $out, 0, 0; my $s = <$out>; next unless $s and $s =~ m/.*\D(\d+)%/s; say STDERR "progress so far: $1 percent"; sleep 1; } } stdout => $out; close $out; __END__ progress so far: 0 percent progress so far: 60 percent progress so far: 70 percent progress so far: 80 percent progress so far: 89 percent progress so far: 99 percent

    I'd prefer to use filehandle opened on Perl scalar, but Capture::Tiny isn't happy about the idea. + You can tee_stdout instead of capture_stdout, to see "normal" output in console, and replace say STDERR ... line with real logic of what you trying to do. Or, to see if something is still happening, just check -s $out for change instead of slurping.

Re^5: Reading progress of "copy" executed asynchronously
by bliako (Monsignor) on Aug 10, 2018 at 09:52 UTC

    You want to say that from cmd.exe copy 'from' 'to' /z reports on progress as it does the copy but when run via Perl's pipe-open it does not update the output until it finishes? In some OSs I find my luck runnning out faster than in others ...

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-25 17:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found