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


Groups > comp.lang.python > #73858

Re: Success with subprocess communicate on Windows?

From Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de>
Subject Re: Success with subprocess communicate on Windows?
Date 2014-07-02 23:22 +0000
References <mailman.11386.1404248789.18130.python-list@python.org> <iq27r9p1gg7nampcd6rr0pftrshinm9oog@4ax.com> <lp0i1p$3gn$1@ger.gmane.org>
Newsgroups comp.lang.python
Message-ID <mailman.11426.1404343384.18130.python-list@python.org> (permalink)

Show all headers | 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