in reply to STDIN connectivity
I think the following code will help you
if (-t STDIN) { print "stdin is connected"; } else { print "stdin is not connected"; } [download]