Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Can't close pipe to invalid process

by Anonymous Monk
on Aug 28, 2015 at 22:03 UTC ( #1140382=note: print w/replies, xml ) Need Help??


in reply to Can't close pipe to invalid process

What am I missing?

Maybe a simpler test case with more diagnostics ( %!, $? )

It could die after the open

Also it could be possible for print to fail and/or kill this "prince" process

  • Comment on Re: Can't close pipe to invalid process

Replies are listed 'Best First'.
Re^2: Can't close pipe to invalid process
by cLive ;-) (Prior) on Aug 28, 2015 at 22:15 UTC

    Well, the print wasn't dying, because the close() test actually runs. BTW, prince is an archaic PDF generator that I've inherited, so I'm just adding tests as I go.

    I guess my concern is why the invalid open returned true. Seems counterintuitive.

      I guess my concern is why the invalid open returned true.

      Because the (piped) open succeeded. It found and successfully ran the prince executable.

      The problem is that you are attributing the failed close to the failure to find the non-existent file; which is wrong.

      What you are attempting to close is the pipe to the prince executable; which fails because the executable closed its end of the pipe, when it terminated because it couldn't find the file.

      Bottom line: You cannot close the pipe because it is already closed. The confusion arises because you are attributing the failed close to the failure of the file to exist; rather than the fact the the pipe was already closed.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
      In the absence of evidence, opinion is indistinguishable from prejudice.
      I'm with torvalds on this Agile (and TDD) debunked I told'em LLVM was the way to go. But did they listen!

        That's completely wrong.

        1. Closing one end of a pipe doesn't cause close on the other end to return an error.

        $ perl -E' pipe($r, $w) or die $!; close($w) or die $!; close($r) or die $!; say "ok"; ' ok

        2. Closing a pipe created by open(my $fh, '|-', ...) reads the process (calls wait). It's very appropriate to do this, whether the pipe is closed or not. Closing such a handle returns the same thing as system.

        $ perl -E' open(my $fh, "|-", "perl", "-e", "exit 123") or die $!; close($fh); die("$!\n") if $? == -1; die("Signal ".( $? & 0x7F )."\n") if $? & 0x7F; die("Error ".( $? >> 8 )."\n") if $? >> 8; say "ok"; ' Error 123

      Well, the print wasn't dying, because the close() test actually runs.

      You mean in your updated new code? Because the code you posted doesn't die if print fails.

      I guess my concern is why the invalid open returned true. Seems counterintuitive.

      Um, if open succeeded, and print succeeded, then it must not have been an invalid open, so nothing counterintuitive there

      Its very possible for a program to end after a successful open to it

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2022-09-29 11:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer my indexes to start at:




    Results (125 votes). Check out past polls.

    Notices?