Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: zcat pipe gives "gzip: stdout: Broken pipe" error

by Special_K (Pilgrim)
on Mar 25, 2025 at 20:00 UTC ( [id://11164425]=note: print w/replies, xml ) Need Help??


in reply to Re: zcat pipe gives "gzip: stdout: Broken pipe" error
in thread zcat pipe gives "gzip: stdout: Broken pipe" error

> In your first code you're not reading the output from zcat so it's griping because you're closing it's output handle "prematurely". If you actually read the output as when you add your while you're hitting EOF and it's happy.

True, but why does the same error not occur when I use that code in a standalone script?

> That being said it really doesn't make sense to stat the filehandle from the pipe read because that's not telling you anything about the underlying file; to get metadata about the path $myfile points to you'd just want to call stat with that path.

According to the official documentation (https://perldoc.perl.org/functions/stat), stat is called using a FILEHANDLE or DIRHANDLE, yet the examples on that page all use stat($filename). I just tested it and calling stat() on a filename returns the exact same value as calling it on an open handle to that filename. The documentation seems to have conflicting information.
  • Comment on Re^2: zcat pipe gives "gzip: stdout: Broken pipe" error

Replies are listed 'Best First'.
Re^3: zcat pipe gives "gzip: stdout: Broken pipe" error
by choroba (Cardinal) on Mar 25, 2025 at 20:46 UTC
    > stat is called using a FILEHANDLE or DIRHANDLE, yet the examples on that page all use stat($filename)

    If the $filehandle is associated with a real file, calling stat on it works the same as using the filename directly. But calling stat on a pipe makes no sense, as Perl has no idea what file(s) the command opens and processes.

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
      > But calling stat on a pipe makes no sense, as Perl has no idea what file(s) the command opens and processes.

      I didn't realize that. In the example from my code where I call stat on the pipe opened to zcat, if I call stat() on the filename and stat() on the open pipe handle and compare the mtime values (last modified), the filename's mtime value is the last modified value as reported in Linux, but the handle's last modified value is the time the pipe was opened.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2026-02-07 10:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.