Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^3: use sysread to read non-blocking filehandle

by x12345 (Novice)
on Nov 04, 2014 at 14:23 UTC ( [id://1106040]=note: print w/replies, xml ) Need Help??


in reply to Re^2: use sysread to read non-blocking filehandle
in thread use sysread to read non-blocking filehandle

If I just use once sysread to try, it is still empty. Here is the code, what is wrong in the code?
my $cmd = '/opt/rssh/bin/ssh'; my $machine = "remote_machine"; open(my $fh, "-|", "$cmd $machine \"hostname;sleep 5;uptime\" 2>&1") o +r die "cannot open fh"; my $flags = fcntl($fh, F_GETFL, 0) or die "\ncan't get flags for the p +ipe: $!\n"; fcntl($fh, F_SETFL, $flags | O_NONBLOCK) or die "\ncan't set flags: $! +\n"; my $out = $fh; my $bytes_read = -1; my $blocksize = 1024; my $result = ""; my $buf; $bytes_read = sysread($out, $buf, $blocksize); print "\nl buf content is:\n $buf \n"; close $out;

Replies are listed 'Best First'.
Re^4: use sysread to read non-blocking filehandle
by Corion (Patriarch) on Nov 04, 2014 at 14:37 UTC

    Maybe you want to learn what "nonblocking" really means?

    In short, "nonblocking" means that the sysread call will return immediately and tell you how many bytes were read at this time. If your filehandle has nothing to read, it will not block. Blocking means "wait until data is avilable".

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-24 01:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found