Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'example:': 0.03; 'argument': 0.05; 'output': 0.05; 'debug': 0.07; 'debugging': 0.07; 'removes': 0.07; 'brad': 0.09; 'line:': 0.09; 'output,': 0.09; 'skip:> 40': 0.09; 'subject:command': 0.09; 'python': 0.11; '%r"': 0.16; '>the': 0.16; 'compute': 0.16; 'did,': 0.16; 'fine.': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'list"': 0.16; 'message- id:@cskk.homeip.net': 0.16; 'outputs': 0.16; 'reproduce': 0.16; 'robust.': 0.16; 'simpson': 0.16; 'skip:> 20': 0.16; 'subject:fails': 0.16; 'supplied': 0.16; 'accordingly.': 0.16; 'files.': 0.16; 'fix': 0.17; 'wrote:': 0.18; 'code.': 0.18; 'trying': 0.19; 'user.': 0.19; 'command': 0.22; 'input': 0.22; 'separate': 0.22; 'shell': 0.22; 'print': 0.22; 'header:User- Agent:1': 0.23; 'error': 0.23; 'stick': 0.24; 'cheers,': 0.24; 'question': 0.24; 'script': 0.25; 'first,': 0.26; 'purposes': 0.26; 'skip:" 40': 0.26; 'post': 0.26; 'code:': 0.26; 'header:In- Reply-To:1': 0.27; 'code': 0.31; "skip:' 10": 0.31; 'bunch': 0.31; 'file': 0.32; 'run': 0.32; 'something': 0.35; 'one,': 0.35; 'but': 0.35; 'skip:> 10': 0.36; 'skip:s 60': 0.36; 'surely': 0.36; 'done': 0.36; 'charset:us-ascii': 0.36; 'should': 0.36; 'error.': 0.37; 'example,': 0.37; 'two': 0.37; 'list': 0.37; 'to:addr :python-list': 0.38; 'files': 0.38; 'skip:- 10': 0.38; 'quote': 0.39; 'to:addr:python.org': 0.39; 'remove': 0.60; 'skip:u 10': 0.60; 'commands': 0.60; 'skip:z 20': 0.60; 'first': 0.61; 'content-disposition:inline': 0.62; 'kind': 0.63; 'more': 0.64; 'hand': 0.80; 'clearly.': 0.84; 'optin': 0.84; 'received:192.168.15': 0.84; 'skip:g 100': 0.84; 'write:': 0.91; 'obtained': 0.96 Date: Sat, 21 Feb 2015 12:11:57 +1100 From: Cameron Simpson To: python-list@python.org Subject: Re: subprocess command fails MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) References: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 98 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1424481128 news.xs4all.nl 2943 [2001:888:2000:d::a6]:58086 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:86004 On 20Feb2015 15:30, Brad s 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 soluti= on 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 y= our=20 question and give some background first, then list offending output with a= =20 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 test1= 23.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 =3D subprocess.call(['dnssec-signzone','-e',strftime('%Y%m%d%H', gm= time())+'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 comm= and=20 line. FOr example, your shell command line supplied the -e optin as=20 "-e20180330000000", but your python code generates two strings: "-e",=20 "20180330000000". It may not matter, but it is not identically worded and some commands are p= icky=20 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 =3D [ 'dnssec-signzone', '-e', strftime('%Y%m%d%H', gmtime())+'0000', '-p',=20 '-t', '-g', '-k', zcombined+'.ksk.key', '-o', dname, dname+'.external', zcombined+'.zsk.key' ] print("command =3D %r" % (cmdargv,)) sfmove =3D 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=20 reproduce the error. Then debug on the command line. Then fix the python co= de=20 accordingly. >#cmd =3D "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 coma= nd=20 =66rom some input line obtained from a user. Stick with your current "const= ruct a=20 list" approach: more robust. I notice your code removes a bunch of files. Might it remove a necessary fi= le=20 for the command? Cheers, Cameron Simpson