Different check to check for CLI
Define STDIN, STDOUT, STDERR ourself when they don't exists
Use $_ENV['PWD'] instead of getcwd().