Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #73858

Re: Success with subprocess communicate on Windows?

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
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; 'subject:Windows': 0.02; 'output': 0.05; 'attribute': 0.07; 'arguments': 0.09; 'exit': 0.09; 'raises': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'try:': 0.09; 'undefined': 0.09; '(taken': 0.16; 'ah,': 0.16; 'cmd': 0.16; 'finds': 0.16; 'idle,': 0.16; 'interpreter,': 0.16; 'message-id:@post.gmane.org': 0.16; 'received:80.91.229.3': 0.16; 'received:mediaways.net': 0.16; 'received:plane.gmane.org': 0.16; 'received:pool.mediaways.net': 0.16; 'reedy': 0.16; 'returncode': 0.16; 'stdin=none,': 0.16; 'used"': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'command': 0.22; '>>>': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'convenient': 0.24; 'logical': 0.24; 'fine': 0.24; 'skip:" 30': 0.26; 'code:': 0.26; 'header:X-Complaints-To:1': 0.27; 'am,': 0.29; 'raise': 0.29; 'tim': 0.29; 'errors': 0.30; 'returned': 0.30; 'said,': 0.30; "i'm": 0.30; 'code': 0.31; '"",': 0.31; 'quotes': 0.31; 'writes:': 0.31; 'file': 0.32; 'skip:c 30': 0.32; 'skip:m 30': 0.32; 'run': 0.32; 'running': 0.33; '(most': 0.33; 'skip:b 30': 0.33; 'sense': 0.34; 'problem': 0.35; 'subject:with': 0.35; 'except': 0.35; 'skip:s 30': 0.35; 'skip:u 20': 0.35; 'but': 0.35; 'raising': 0.36; 'charset:us-ascii': 0.36; 'subject:?': 0.36; 'so,': 0.37; 'window': 0.38; 'to:addr:python-list': 0.38; 'recent': 0.39; 'does': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'received:org': 0.40; 'hope': 0.61; 'helps': 0.61; 'first': 0.61; 'name': 0.63; 'more': 0.64; 'finally': 0.65; 'console,': 0.84; "everything's": 0.84; 'whereas': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de>
Subject Re: Success with subprocess communicate on Windows?
Date Wed, 2 Jul 2014 23:22:50 +0000 (UTC)
References <mailman.11386.1404248789.18130.python-list@python.org> <iq27r9p1gg7nampcd6rr0pftrshinm9oog@4ax.com> <lp0i1p$3gn$1@ger.gmane.org>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host sea.gmane.org
User-Agent Loom/3.14 (http://gmane.org/)
X-Loom-IP 77.2.139.225 (Mozilla/5.0 (Windows NT 6.1; WOW64; rv:30.0) Gecko/20100101 Firefox/30.0)
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.11426.1404343384.18130.python-list@python.org> (permalink)
Lines 81
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1404343384 news.xs4all.nl 2901 [2001:888:2000:d::a6]:59145
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:73858

Show key headers only | View raw


Terry Reedy <tjreedy <at> udel.edu> writes:

> 
> On 7/2/2014 12:33 AM, Tim Roberts wrote:
> > Terry Reedy <tjreedy <at> udel.edu> wrote:
> >>
> > You need to use
> >      s.check_output("pyflakes c:\\programs\\python34\\lib\\turtle.py")
> > or
> >      s.check_output(r"pyflakes c:\programs\python34\lib\turtle.py")
> 
> Now I get "Command 'pyflakes c:\programs\python34\lib\turtle.py' returns 
> non-zero exit status 1" on both. On Idle, as least, a command-prompt 
> window is flashed/displayed. It makes no sense to me that in the command 
> interpreter,
> 'pyflakes c:\\programs\\python34\\lib' works and
> 'pyflakes c:\\programs\\python34\\lib\\turtle.py' returns status 1.
> whereas both (with quotes elided and undoubled \) work at the command 
> prompt.
> 

Finally found out what the problem is:
When I'm running your command using the cmd console, I get this output:

c:\python34\lib\turtle.py:571: local variable 'rgb' is assigned to but never
used
c:\python34\lib\turtle.py:2936: local variable 'a21' is assigned to but
never used
c:\python34\lib\turtle.py:3590: local variable 'dummy' is assigned to but
never used
c:\python34\lib\turtle.py:3786: undefined name 'mainloop'
c:\python34\lib\turtle.py:3969: undefined name 'mainloop'
c:\python34\lib\turtle.py:3973: undefined name 'isdown'
c:\python34\lib\turtle.py:3974: undefined name 'pu'
c:\python34\lib\turtle.py:3976: undefined name 'pd'
..

now look at the exit code:
echo %errorlevel%
1

ah, pyflakes does exit with a non-zero exit code when it finds errors in
your file!!

Now, using subprocess.check_output in IDLE:

>>> msg=subprocess.check_output(r'pyflakes c:\python34\lib\turtle.py')
Traceback (most recent call last):
  File "<pyshell#45>", line 1, in <module>
    msg=subprocess.check_output(r'pyflakes c:\python34\lib\turtle.py')
  File "C:\Python34\lib\subprocess.py", line 618, in check_output
    raise CalledProcessError(retcode, process.args, output=output)
subprocess.CalledProcessError: Command 'pyflakes c:\python34\lib\turtle.py'
returned non-zero exit status 1

as you said, but logical since (taken from the docs):

"subprocess.check_output(args, *, input=None, stdin=None, stderr=None,
shell=False, universal_newlines=False, timeout=None) 
Run command with arguments and return its output.

If the return code was non-zero it raises a CalledProcessError. The
CalledProcessError object will have the return code in the returncode
attribute and any output in the output attribute."

and in fact:
>>> try:
	msg=subprocess.check_output(r'pyflakes c:\python34\lib\turtle.py')
except subprocess.CalledProcessError as e:
	print (e.output[:81])

	
b"c:\\python34\\lib\\turtle.py:571: local variable 'rgb' is assigned to but
never used"

So, everything's just fine except that it may be more convenient to use
Popen().communicate() to avoid raising the error in the first place :)

Hope it helps this time,
Wolfgang

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Success with subprocess communicate on Windows? Terry Reedy <tjreedy@udel.edu> - 2014-07-01 17:05 -0400
  Re: Success with subprocess communicate on Windows? Tim Roberts <timr@probo.com> - 2014-07-01 21:33 -0700
    Re: Success with subprocess communicate on Windows? Terry Reedy <tjreedy@udel.edu> - 2014-07-02 05:05 -0400
    Re: Success with subprocess communicate on Windows? Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> - 2014-07-02 19:31 +0200
    Re: Success with subprocess communicate on Windows? Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> - 2014-07-02 19:37 +0200
    Re: Success with subprocess communicate on Windows? Terry Reedy <tjreedy@udel.edu> - 2014-07-02 19:14 -0400
    Re: Success with subprocess communicate on Windows? Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> - 2014-07-02 23:22 +0000
    Re: Success with subprocess communicate on Windows? Ethan Furman <ethan@stoneleaf.us> - 2014-07-02 16:54 -0700
    Re: Success with subprocess communicate on Windows? Terry Reedy <tjreedy@udel.edu> - 2014-07-03 00:09 -0400
    Re: Success with subprocess communicate on Windows? Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> - 2014-07-03 10:03 +0200
    Re: Success with subprocess communicate on Windows? Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> - 2014-07-03 11:22 +0200

csiph-web