By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,766 Members | 1,427 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,766 IT Pros & Developers. It's quick & easy.

Finding Return Code From GPG

P: n/a
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?

Jul 4 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Nomen Nescio wrote:
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
Jul 4 '06 #2

P: n/a
* Dennis Benzinger <De**************@gmx.net>:
Nomen Nescio wrote:
I'm running gpg in python to verify a signature.
But I need a way to let the python script know this.
I have written a script to verify signatures using gpg some time
ago, maybe this helps you:

http://old.homeip.net/martin/sigcheck/

bye
Martin

Jul 6 '06 #3

P: n/a
On Tue, 04 Jul 2006 19:00:23 +0200, Dennis Benzinger wrote:
Nomen Nescio wrote:
>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>.
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 <sc*****@test.invalid>"
I need to get that into a file so I can parse it. Any further suggestions?

Jul 7 '06 #4

P: n/a
>>>>Nomen Nescio <no****@dizum.com(NN) wrote:
>NNThanks, I used the popen function which did some of what I want. Here is
NNthe code I used:
>NNfrom subprocess import *
>NNoutput = Popen(["gpg", "--output", "--verify", "sigtest"], stdout=PIPE).communicate()[0]
You need a filename argument for --output.
>NNThat worked, sort of - it did the verification at least and I can see
NNthe return code.
>NNWhat is still not working is the display from gpg. It shows up on the
NNmonitor screen like this:
>NNgpg: Signature made Tue 04 Jul 2006 08:04:10 AM CET using DSA key ID
NN06B09BA4
NNgpg: Good signature from "Boz Scraggs <sc*****@test.invalid>"
>NNI 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]
--
Piet van Oostrum <pi**@cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: pi**@vanoostrum.org
Jul 7 '06 #5

P: n/a
On Sat, 08 Jul 2006 00:26:06 +0200, Piet van Oostrum wrote:
>
>>NNWhat is still not working is the display from gpg. It shows up on the
NNmonitor screen like this:
>>NNgpg: Signature made Tue 04 Jul 2006 08:04:10 AM CET using DSA key ID
NN06B09BA4
NNgpg: Good signature from "Boz Scraggs <sc*****@test.invalid>"
>>NNI 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.



Jul 13 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.