Ok - well for my purposes, let's say we're not running in a console. We could be called from a Win32::Daemon service. So I'm trying to determine whether I'm running in a console (or terminal session) or not. So let me rephrase, The solution doesn't need to be generic. I can just have a condition to see if I'm running on Windows or *nix, and then do the appropriate check ... but I still need to know what the check would be
| [reply] |
if (-t STDIN) { ...
| [reply] [d/l] |
Good, but not sufficient. Input may come from a pipe or a file, so you also should check STDOUT. But even that is not sufficient, because STDOUT could be redirected or piped, too, so you may also want to check STDERR. And, you may already have guessed that, even that is not sufficient, as also STDERR can be piped or redirected.
If you have a dual-mode script that can work both as a daemon ("background process") and as an interactive command, use a command line switch for the daemon mode. Make the daemon starter (daemontools, init, srvany.exe) pass that switch to your command. Alternatively, use a symbolic link and decide based on $0, or use two scripts that have their shared code in one or more modules.
Alexander
--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
| [reply] [d/l] |