Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

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

by zentara (Archbishop)
on Aug 08, 2018 at 12:03 UTC ( [id://1220082]=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

Hi, I don't know how it is done on Windows, but I suspect you need to turn off buffering of STDOUT to get immediate readout. Try using $|=1 to turn off STDOUT buffering. Also see Is print faster than syswrite? and Re^3: explanation for sysread and syswrite for examples on using syswrite and sysread. If you write your own copying program with syswrite and turn stdout buffering off, you should be able to monitor your instantaneous progress. Look at this example from the perlmonks archives:
#!/usr/bin/perl -w use strict; use IPC::Open2; use IO::Select; $| = 1; # autoflush STDOUT # Declare filehandles and command to use: my ($r, $w); my $cmd = 'ping 127.0.0.1'; # Open the process and set the selector: my $pid = open2($r, $w, $cmd); my $selector = IO::Select->new($r); while (1) # infinite loop (use "last" to break out) { if ($selector->can_read(0)) { my $chars; my $bytes_read = sysread($r, $chars, 4046); print "$bytes_read $chars\n"; } # Do anything you want in between reads here... } __END__ The advantage to this script is that, if your commands (like "whois", "dig", and "ping") happen to pause, the loop won't automatically break out. The disadvantage to this script is that it might be difficult figuring out when a command has finished, or just has delayed output (in which case you might have to put in a few sleep() calls). Either way, I think that this script here does a better job of helping you visualize what is going on -- you just need to be mindful of the fact that some programs don't flush their output right away, and that it's not a simple matter to tell if the program has stopped running altogether.

I'm not really a human, but I play one on earth. ..... an animated JAPH

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-03-29 08:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found