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


Groups > comp.lang.python > #108078

Re: Saving Consol outputs in a python script

From Stephen Hansen <me+python@ixokai.io>
Newsgroups comp.lang.python
Subject Re: Saving Consol outputs in a python script
Date 2016-05-03 08:43 -0700
Message-ID <mailman.348.1462290243.32212.python-list@python.org> (permalink)
References <b188eaaf-7945-4f40-9cfc-f56dd3f34407@googlegroups.com> <1462290239.1609819.596871457.7356F4C8@webmail.messagingengine.com>

Show all headers | View raw


On Tue, May 3, 2016, at 05:14 AM, drewes.mil@gmail.com wrote:
> What I need are the 2 values for the 2 classes saved in a variable in the
> .py script, so that I can write them into a text file.
> 
> Would be super nice if someone could help me!

You shouldn't use the call() convienence function, but instead create a
process using the Popen constructor, passing PIPE to stdout. Then use
communicate() to get the output.

This should get you started:

    process = subprocess.Popen(["commandline"], stdout=subprocess.PIPE)
    output, error = process.communicate()

Output will be a string, string has a splitlines method, etc.

-- 
Stephen Hansen
  m e @ i x o k a i . i o

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


Thread

Saving Consol outputs in a python script drewes.mil@gmail.com - 2016-05-03 05:14 -0700
  Re: Saving Consol outputs in a python script DFS <nospam@dfs.com> - 2016-05-03 10:32 -0400
  Re: Saving Consol outputs in a python script Stephen Hansen <me+python@ixokai.io> - 2016-05-03 08:43 -0700
  Re: Saving Consol outputs in a python script Terry Reedy <tjreedy@udel.edu> - 2016-05-03 12:50 -0400

csiph-web