Separate stdout and stderr -- Any Command or shell script??

Steven W. Orr steveo at
Wed Jun 24 16:07:30 CEST 2009

Hash: SHA1

On 06/24/09 02:56, quoth littleBrain:
> Hi All, 
> I am newbie to GPG. 
> I have got an application where it uses the following command to decrypt GPG
> encrypted messages. 
> /usr/local/bin/gpg --no-tty --passphrase-fd 0 -d /tmp/testXXXXXX.gpg 
> This often (at least rarely) returns an error. One such example is: 
> Decrypted message body 
> =-=-=-=-=-= 
> ----cut---- 
>       } 
> !     sprintf(prime_arg, "%s to %s", prime_arg1, prime_arg2); 
>    gpg: Signature made Fri May 25 13:11:36 2007 PDT using DSA key ID *******
> gpg: Good signature from "****************" 
> gpg: WARNING: message was not integrity protected 
>    ret.code = KADM5_OK; 
>       if (! CHANGEPW_SERVICE(rqstp)) { 
> --- 573,586 ---- 
> ----cut---- 
> =-=-=-=-=-=-=-=-=- 
> Key ID and email is deleted for security reasons.
> And I see, error and the decrypted message (stdOut??) are spewed out in the
> body. 
> I would like to separate these error messages to bottom of the message and
> standard decrypted output to the top of the body. 
> Could someone please help me to use some command or a shell script to
> achieve this? 
> Any help would be highly appreciated... 

When a program writes to stdout it goes to channel 1. stderr is channel 2. So
if you do something like

pgp [args] 1> out 2> err

then you can do separate things with the output versus the error channels.

You can try it yourself. Just run your command different ways:

cmd 1> /dev/null       # See only error messages
cmd 2> /dev/null       # See only the output and discard the error channel
cmd 2>&1               # See all of the output and error channel
                       # all delivered to the output channel
cmd 1>&2               # Send everything to the error channel
cmd > outpluserror 2>&1 # Put both output and errors into one file.

Wasn't that easy?

Make sense?

> ~ 
> littleBrain

- --
Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at
Version: GnuPG v2.0.10 (GNU/Linux)
Comment: Using GnuPG with Fedora -


More information about the Gnupg-users mailing list