Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: More pipe problems

by spudzeppelin (Pilgrim)
on Jul 19, 2001 at 00:00 UTC ( [id://97864]=note: print w/replies, xml ) Need Help??


in reply to More pipe problems

Actually, the explanation behind this one is even simpler. You're opening a pipe to perl, with "non-existant_file" called as an argument. That pipe will succeed; perl will be opened, and subsequently exit, but the point is that the "open" call itself was successful -- you were able to open a handle to a perl process.

The cheap and easy way around this is to make sure that whatever you intend to open on a pipe is executable and has the shebang at the top, and omit the perl. e.g.:

#!/usr/bin/perl use strict; open (PIPE,"|non-existant_file") or die "Can't open pipe: $!"; print "hello"; sleep 5; print "goodbye";

This way, when non-existant_file fails to execute, the open call fails, and you should die the way you intended.

As an aside, it doesn't even have to be perl inside the pipe for this to be a factor. This could just as easily have been a pipe to awk or gzip or foobarbazwhee with incorrect arguments -- as long as the right-hand side of the pipe is, in fact, invoked, open doesn't fail.

Spud Zeppelin * spud@spudzeppelin.com

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-03-29 04:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found