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


Groups > comp.lang.python > #45785

Re: newbie question about subprocess.Popen() arguments

References <CABPy6+wGwvkyrq06k87hZfDO2-bNxsw72RNKyDq9hng_QwNPVw@mail.gmail.com> <knkglq$8mr$1@ger.gmane.org>
Date 2013-05-23 09:40 +0200
Subject Re: newbie question about subprocess.Popen() arguments
From Alex Naumov <alexander_naumov@opensuse.org>
Newsgroups comp.lang.python
Message-ID <mailman.2002.1369294855.3114.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

Thank you very much, Peter!
It works!


On Thu, May 23, 2013 at 9:32 AM, Peter Otten <__peter__@web.de> wrote:

> 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]
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

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


Thread

Re: newbie question about subprocess.Popen() arguments Alex Naumov <alexander_naumov@opensuse.org> - 2013-05-23 09:40 +0200

csiph-web