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


Groups > comp.lang.python > #45783 > unrolled thread

Re: newbie question about subprocess.Popen() arguments

Started byPeter Otten <__peter__@web.de>
First post2013-05-23 09:32 +0200
Last post2013-05-23 09:32 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: newbie question about subprocess.Popen() arguments Peter Otten <__peter__@web.de> - 2013-05-23 09:32 +0200

#45783 — Re: newbie question about subprocess.Popen() arguments

FromPeter Otten <__peter__@web.de>
Date2013-05-23 09:32 +0200
SubjectRe: newbie question about subprocess.Popen() arguments
Message-ID<mailman.2000.1369294348.3114.python-list@python.org>
Alex Naumov wrote:

> I'm trying to call new process with some parameters. The problem is that
> the last parameter is a "string" that has a lot of spaces and different
> symbols like slash and so on. I can save it in file and use name of this
> file as parameter, but my question is: how to make it without   additional
> saving?
> 
> import subprocess as sp
> 
> rc = sp.Popen(["prog", "--options", "<", msg], stdin=sp.PIPE,
> stdout=sp.PIPE)
> stdout = rc.communicate()[0]
> print stdout

> p.s.
> type(msg) => <type 'str'>

The < operator is a shell feature, not an argument, and msg is intended to 
be send to prog's stdin. The communicate() method accepts a parameter for 
that. So:

rc = sp.Popen(["prog", "--options"], stdin=sp.PIPE, stdout=sp.PIPE)
stdout = rc.communicate(msg)[0]

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web