Finding Return Code From GPG

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nomen Nescio

    #1

    Finding Return Code From GPG

    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?

  • Dennis Benzinger

    #2
    Re: Finding Return Code From GPG

    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

    Comment

    • Martin Renold

      #3
      Re: Finding Return Code From GPG

      * Dennis Benzinger <Dennis.Benzing er@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:



      bye
      Martin

      Comment

      • Nomen Nescio

        #4
        Re: Finding Return Code From GPG

        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).co mmunicate()[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 <scraggs@test.i nvalid>"


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

        Comment

        • Piet van Oostrum

          #5
          Re: Finding Return Code From GPG

          >>>>Nomen Nescio <nobody@dizum.c om(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).co mmunicate()[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 <scraggs@test.i nvalid>"
          >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).co mmunicate()[1]
          --
          Piet van Oostrum <piet@cs.uu.n l>
          URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C 4]
          Private email: piet@vanoostrum .org

          Comment

          • Nomen Nescio

            #6
            Re: Finding Return Code From GPG

            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 <scraggs@test.i nvalid>"
            >
            >>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).co mmunicate()[1]
            That worked, thanks very much; and my thanks to all who replied.









            Comment

            Working...