Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #86004
| Date | 2015-02-21 12:11 +1100 |
|---|---|
| From | Cameron Simpson <cs@zip.com.au> |
| Subject | Re: subprocess command fails |
| References | <c03d11a3-33d3-4b8c-a966-34181e1b5bfd@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.18940.1424481128.18130.python-list@python.org> (permalink) |
On 20Feb2015 15:30, Brad s <bcddd214@gmail.com> wrote:
>I am trying to execute a subprocess, something done in my script a couple of times. But on the last one, it outputs an error I cannot find the solution to. The exact same command using the same files produced at the command line works just fine.
>
Hi Brad,
I have reordered your post in my quote for readability. It is best to ask your
question and give some background first, then list offending output with a
description of good output, then the code.
You write:
>The first command works on the command line:
>
>dnssec-signzone -e20180330000000 -p -t -g -k Ktest123.com.ksk.key -o test123.com test123.com.external Ktest123.com.zsk.key
>Verifying the zone using the following algorithms: RSASHA256.
>Zone fully signed:
>Algorithm: RSASHA256: KSKs: 1 active, 0 stand-by, 0 revoked
> ZSKs: 1 active, 0 stand-by, 0 revoked
>test123.com.external.signed
>Signatures generated: 9
>Signatures retained: 0
>Signatures dropped: 0
>Signatures successfully verified: 0
>Signatures unsuccessfully verified: 0
>Signing time in seconds: 0.010
>Signatures per second: 875.401
>Runtime in seconds: 0.013
Which is excellent.
Then you supply your code:
>sfmove = subprocess.call(['dnssec-signzone','-e',strftime('%Y%m%d%H', gmtime())+'0000','-p','-t','-g','-k',zcombined+'.ksk.key','-o',dname,dname+'.external',zcombined+'.zsk.key'])
I would start by pointing out that this is not identical to your shell command
line. FOr example, your shell command line supplied the -e optin as
"-e20180330000000", but your python code generates two strings: "-e",
"20180330000000".
It may not matter, but it is not identically worded and some commands are picky
about this kind of thing.
For debugging purposes I would do two things:
- compute the python command argument list as a separate list and print it out, example:
cmdargv = [ 'dnssec-signzone',
'-e', strftime('%Y%m%d%H', gmtime())+'0000',
'-p',
'-t',
'-g',
'-k', zcombined+'.ksk.key',
'-o', dname,
dname+'.external',
zcombined+'.zsk.key'
]
print("command = %r" % (cmdargv,))
sfmove = subprocess.call(cmdargv)
Note the use of %r to print the contents of the command clearly.
(BTW, "sfmove"? Surely "sign" or something.)
- hand run _exactly_ the command printed out by the print call above
If you run _exactly_ what your python comman did, you should be able to
reproduce the error. Then debug on the command line. Then fix the python code
accordingly.
>#cmd = "dnssec-signzone','-e',strftime('%Y%m%d%H', gmtime())+'0000','-p','-t','-g','-k','K'+dname+'.ksk.key','-o',dname,dname+'.external','K"+dname+'.zsk.key'
>#subprocess.check_call(shlex.split(cmd))
Remark: shlex.split is not a good way to make a command line unless it comand
from some input line obtained from a user. Stick with your current "construct a
list" approach: more robust.
I notice your code removes a bunch of files. Might it remove a necessary file
for the command?
Cheers,
Cameron Simpson <cs@zip.com.au>
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
subprocess command fails Brad s <bcddd214@gmail.com> - 2015-02-20 15:30 -0800
Re: subprocess command fails Cameron Simpson <cs@zip.com.au> - 2015-02-21 12:11 +1100
Re: subprocess command fails Brad s <bcddd214@gmail.com> - 2015-02-20 20:47 -0800
Re: subprocess command fails Larry Hudson <orgnut@yahoo.com> - 2015-02-21 12:33 -0800
Re: subprocess command fails Brad s <bcddd214@gmail.com> - 2015-02-20 21:14 -0800
Re: subprocess command fails Cameron Simpson <cs@zip.com.au> - 2015-02-21 17:47 +1100
Re: subprocess command fails Brad s <bcddd214@gmail.com> - 2015-02-20 22:41 -0800
csiph-web