How does it "not work" when run from your script?
My guess is that there is either a problem with licensing, or with finding the appropriate keys.
Add "pgp --version --verbose" to the front of your SAP script and look for differences in the "File information" and "Licensing" sections, compared to running it from the OS prompt.