Finding Return Code From GPG

N

Nomen Nescio

I'm running gpg in python to verify a signature. I can see that it is
working, because gpg is displaying the results.

But I need a way to let the python script know this. According to the gpg
manual there is a return code from gpg of 0 if the verify is good and 1 if
it is bad.

Can anyone tell me how I can get the python script to 'see' this return
code?
 
D

Dennis Benzinger

Nomen said:
I'm running gpg in python to verify a signature. I can see that it is
working, because gpg is displaying the results.

But I need a way to let the python script know this. According to the gpg
manual there is a return code from gpg of 0 if the verify is good and 1 if
it is bad.

Can anyone tell me how I can get the python script to 'see' this return
code?

How do you run GPG? I suggest using the subprocess module
<http://docs.python.org/lib/module-subprocess.html>. If you just need
something simple then you can use its call function
<http://docs.python.org/lib/node236.html>.


Bye,
Dennis
 
N

Nomen Nescio

How do you run GPG? I suggest using the subprocess module
<http://docs.python.org/lib/module-subprocess.html>. If you just need
something simple then you can use its call function
<http://docs.python.org/lib/node236.html>.

Thanks, I used the popen function which did some of what I want. Here is
the code I used:


from subprocess import *

output = Popen(["gpg", "--output", "--verify", "sigtest"], stdout=PIPE).communicate()[0]



That worked, sort of - it did the verification at least and I can see the return code.

What is still not working is the display from gpg. It shows up on the monitor screen like this:

gpg: Signature made Tue 04 Jul 2006 08:04:10 AM CET using DSA key ID
06B09BA4
gpg: Good signature from "Boz Scraggs <[email protected]>"


I need to get that into a file so I can parse it. Any further suggestions?
 
P

Piet van Oostrum

Nomen Nescio said:
NN> Thanks, I used the popen function which did some of what I want. Here is
NN> the code I used:
NN> from subprocess import *
NN> output = Popen(["gpg", "--output", "--verify", "sigtest"], stdout=PIPE).communicate()[0]

You need a filename argument for --output.
NN> That worked, sort of - it did the verification at least and I can see
NN> the return code.
NN> What is still not working is the display from gpg. It shows up on the
NN> monitor screen like this:
NN> gpg: Signature made Tue 04 Jul 2006 08:04:10 AM CET using DSA key ID
NN> 06B09BA4
NN> gpg: Good signature from "Boz Scraggs <[email protected]>"
NN> I need to get that into a file so I can parse it. Any further suggestions?

That output is passed to stderr. So you can get it in a string:

output = Popen(["gpg", "--output", "outfile", "--verify", "sigtest"], stderr=PIPE).communicate()[1]
 
N

Nomen Nescio

NN> What is still not working is the display from gpg. It shows up on the
NN> monitor screen like this:
NN> gpg: Signature made Tue 04 Jul 2006 08:04:10 AM CET using DSA key ID
NN> 06B09BA4
NN> gpg: Good signature from "Boz Scraggs <[email protected]>"
NN> I need to get that into a file so I can parse it. Any further suggestions?

That output is passed to stderr. So you can get it in a string:

output = Popen(["gpg", "--output", "outfile", "--verify", "sigtest"], stderr=PIPE).communicate()[1]

That worked, thanks very much; and my thanks to all who replied.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top