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

Re: Can a script tell if it is being run from inside a script versus in an interactive terminal session?

by BrowserUk (Patriarch)
on Nov 07, 2014 at 20:59 UTC ( [id://1106532]=note: print w/replies, xml ) Need Help??


in reply to Can a script tell if it is being run from inside a script versus in an interactive terminal session?

You might try seeking on STDIN. If its connected to a redirected file, it should succeed; if its a pipe it will fail:

C:\test>perl -E"seek STDIN, 0,0 or die $!" <junk.txt C:\test>echo junk.txt | perl -E"seek STDIN, 0,0 or die $!" Invalid seek at -e line 1.

Put the seek in a die block and check for the error condition.


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".
In the absence of evidence, opinion is indistinguishable from prejudice.
  • Comment on Re: Can a script tell if it is being run from inside a script versus in an interactive terminal session?
  • Download Code

Log In?
Username:
Password:

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

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

    No recent polls found