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


Groups > comp.lang.python > #32494

RE: how to change os.popen4 to subprocess

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ramit.prasad@jpmorgan.com>
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; '"""': 0.05; 'mrab': 0.05; '[0]': 0.07; 'arguments': 0.07; 'completeness': 0.07; 'deprecated': 0.07; 'line:': 0.07; 'scripts': 0.09; 'python': 0.09; 'indicates': 0.09; 'porting': 0.09; 'received:155': 0.09; 'stderr': 0.09; 'tuple': 0.09; 'suggest': 0.11; 'disclaimers': 0.16; 'disclaimers,': 0.16; 'from:addr:jpmorgan.com': 0.16; 'hazard': 0.16; 'input.': 0.16; 'invoking': 0.16; 'module:': 0.16; 'oct': 0.16; 'received:155.180': 0.16; 'received:159.53': 0.16; 'received:159.53.110': 0.16; 'received:bankone.net': 0.16; 'received:exchad.jpmchase.net': 0.16; 'received:jpmchase.com': 0.16; 'received:jpmchase.net': 0.16; 'received:svr.bankone.net': 0.16; 'securities,': 0.16; 'stdout:': 0.16; 'subprocess': 0.16; 'url:disclosures': 0.16; 'url:jpmorgan': 0.16; 'wrote:': 0.17; 'received:169.254.1': 0.17; 'shell': 0.18; 'to:name:python- list@python.org': 0.20; 'trying': 0.21; 'parse': 0.22; 'this:': 0.23; 'received:169.254': 0.24; 'command': 0.24; 'header:In-Reply- To:1': 0.25; '[1]': 0.27; 'accuracy': 0.27; 'member.': 0.27; 'piece': 0.29; 'received:169': 0.29; "i'm": 0.29; 'usually': 0.30; 'figure': 0.30; 'helpful': 0.30; 'code': 0.31; 'gets': 0.32; 'url:python': 0.32; 'anybody': 0.32; 'could': 0.32; 'skip:s 30': 0.33; 'subject:change': 0.33; 'to:addr:python-list': 0.33; 'hi,': 0.33; 'thanks': 0.34; 'url:org': 0.36; 'url:library': 0.36; 'should': 0.36; 'does': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'url:docs': 0.38; 'to:addr:python.org': 0.39; 'information,': 0.63; 'url:email': 0.63; 'replying': 0.64; 'here': 0.65; 'legal': 0.65; 'frequently': 0.65; 'subject': 0.66; 'purchase': 0.67; 'sale': 0.76; 'case?': 0.84; 'explanation:': 0.84
X-DKIM OpenDKIM Filter v2.1.3 sj3.jpmchase.com q9UEm2ka022972
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpmorgan.com; s=smtpout; t=1351608482; bh=BmFCm7qtiRlB6sRT4Be2oVqpjqYh5pbO/bOhoeUhUEc=; h=From:To:Subject:Date:Message-ID:References:In-Reply-To: Content-Transfer-Encoding:MIME-Version:Content-Type; b=O4deuKAIppBb1kmt46xJVwpt6E3vk4dTmxHTtEN7NxF6EzvdhYSIKhm9spMfvTQri dH394bwDIhcbtgtIfTUUFLpsUoT7ohfIFaA55em1PzIKMQEn2oPYGrUVgg/N42tPWH 8uk/vJxVHwFN4pEr9b6DVDvYCl6YiJl1v+D0LUSY=
From "Prasad, Ramit" <ramit.prasad@jpmorgan.com>
To "python-list@python.org" <python-list@python.org>
Subject RE: how to change os.popen4 to subprocess
Thread-Topic how to change os.popen4 to subprocess
Thread-Index AQHNtAycUw8lyDVGdUKeRwnlGtlGl5fQ2hxA
Date Tue, 30 Oct 2012 14:47:52 +0000
References <c6bac1cc-abda-4d95-b3b4-e96dc7ab7a3a@r8g2000pbs.googlegroups.com> <mailman.2928.1351306928.27098.python-list@python.org> <ea712e7b-bad9-4763-bbae-22a824f07256@qi8g2000pbb.googlegroups.com>
In-Reply-To <ea712e7b-bad9-4763-bbae-22a824f07256@qi8g2000pbb.googlegroups.com>
Accept-Language en-US
Content-Language en-US
X-MS-Has-Attach
X-MS-TNEF-Correlator
x-originating-ip [10.67.79.47]
Content-Transfer-Encoding quoted-printable
MIME-Version 1.0
X-DLP-FWD Yes
Content-Type text/plain; charset="iso-8859-1"
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 <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3093.1351608486.27098.python-list@python.org> (permalink)
Lines 30
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1351608487 news.xs4all.nl 6894 [2001:888:2000:d::a6]:59874
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:32494

Show key headers only | View raw


Replying to skyworld because I could not find the original message
from MRAB.

skyworld wrote:
> On Oct 27, 11:02 am, MRAB <pyt...@mrabarnett.plus.com> wrote:
> > On 2012-10-27 03:28, skyworld wrote:> Hi,
> >
> > > I'm new to python and I'm trying to porting some scripts from v0.96 to
> > > v2.0.1. A piece of code is like this:
> >
> > > cmd_h = os.popen4(env['SYSCMDLINE'])[1]
> >
> > > the system indicates the popen4 is deprecated and suggest to use
> > > subprocess. Can anybody tell me how to use subprocess in this case?
> > > and what does "[1]" here means?
> >
> > os.popen4 returns a tuple of (child_stdin, child_stdout_and_stderr).
> > The [1] gets the child_stdout_and_stderr member.
> >
> > Using the subprocess module:
> >
> > # Untested!
> > cmd_h = subprocess.Popen(env['SYSCMDLINE'], stdout=subprocess.PIPE,
> > stderr=subprocess.STDOUT, shell=True).stdout
> >
> > Explanation:
> >
> > The command line: env['SYSCMDLINE']
> >
> > Return stdout: stdout=subprocess.PIPE
> >
> > stderr should be combined with stdout: stderr=subprocess.STDOUT
> >
> > Let the shell parse the command line: shell=True
> 
> thanks
> --

I thought the usage of shell=True is usually discouraged? The 
subprocess documentation[0] should be helpful to figure it out.
"""
Warning: Invoking the system shell with shell=True can be a security 
hazard if combined with untrusted input. See the warning under 
Frequently Used Arguments for details.
"""

[0] http://docs.python.org/2/library/subprocess.html 


Ramit


This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  

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


Thread

how to change os.popen4 to subprocess skyworld <chenyong20000@gmail.com> - 2012-10-26 19:28 -0700
  Re: how to change os.popen4 to subprocess MRAB <python@mrabarnett.plus.com> - 2012-10-27 04:02 +0100
    Re: how to change os.popen4 to subprocess skyworld <chenyong20000@gmail.com> - 2012-10-26 23:30 -0700
      RE: how to change os.popen4 to subprocess "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-10-30 14:47 +0000
  Re: how to change os.popen4 to subprocess Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-10-27 04:10 +0100

csiph-web