As Riamus stated, it works properly from the command line, but not when done from a script.