Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

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

by neWerminder (Novice)
on Aug 09, 2018 at 04:44 UTC ( [id://1220137]=note: print w/replies, xml ) Need Help??


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

hey, none of the above works on Windows unfortunately. First option is out due to -| which apparently is not supported on windows. I receive "List form of pipe open not implemented". Second option wont work because windows for some reason shows that size of file "to" is same as size of file "from" in the moment copying started.. ;/ at least in any of methods i know.
  • Comment on Re^2: Reading progress of "copy" executed asynchronously

Replies are listed 'Best First'.
Re^3: Reading progress of "copy" executed asynchronously
by bliako (Monsignor) on Aug 09, 2018 at 10:22 UTC

    I was not aware Windows reports incorrect filesizes. Then you have to rely on copy's reporting. Use this pipe-open form instead:

    use strict; use warnings; my $cmd = 'copy.exe 'from', 'to', '/z' |'; open(EXE, $cmd) || die "$!"; while(<EXE>){ print "read from program output: ".$_."\n"; } print "done.\n"; close(EXE);

    Or use IPC::Run or any other IPC::* module mentioned here or there.

      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

        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.

        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://1220137]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-26 01:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found