Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: How do I Determine if my script is being piped to?

by kschwab (Vicar)
on Nov 21, 2013 at 00:11 UTC ( [id://1063638]=note: print w/replies, xml ) Need Help??


in reply to How do I Determine if my script is being piped to?

You can tell if STDIN is a tty or not, which isn't quite the same thing, but it might suffice:
#!/usr/bin/perl use POSIX qw(isatty); if (isatty(STDIN)) { die("nope. not like that\n"); } while (<>) { print "$_\n"; }

Replies are listed 'Best First'.
Re^2: How do I Determine if my script is being piped to?
by netguy (Novice) on Nov 21, 2013 at 00:42 UTC

    Thanks much for the reply. I didn't expect an answer so fast or that it would provide the solution.

    Though the example you gave doesn't work, maybe because of 'use strict;' , I did find a couple things that do work. If I did have a better understanding of Linux, I may have found the answer on my own. Just something I'll have to work on.

    Here are a couple examples of what did work for me:
    use strict; if ( -t STDIN ) { print "This is what you're supposed to do ...\n"; exit; } # or use POSIX qw(isatty); if ( isatty(\*STDIN) ) { print "This is what you're supposed to do ...\n"; exit; } while (<STDIN>) { print STDOUT "Add something to STDOUT".$_; }

    Thanks for the help. It wasn't a show-stopping feature, just trying to mitigate confusion by some users when the command is run and the cursor just sits there doing nothing.
Re^2: How do I Determine if my script is being piped to?
by boftx (Deacon) on Nov 21, 2013 at 00:16 UTC

    Well, kschwab has a much better memory that I do. You can pretty much ignore what I was posting at the same time he was giving you the answer I was looking for. :)

    It helps to remember that the primary goal is to drain the swamp even when you are hip-deep in alligators.

Log In?
Username:
Password:

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

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

    No recent polls found