Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #43893 > unrolled thread
| Started by | Ombongi Moraa Fe <moraa.lovetakes2@gmail.com> |
|---|---|
| First post | 2013-04-19 12:56 +0300 |
| Last post | 2013-04-19 14:43 +0000 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.lang.python
RE: subprocess.call Ombongi Moraa Fe <moraa.lovetakes2@gmail.com> - 2013-04-19 12:56 +0300
Re: subprocess.call Mau C <nobody@hotmail.com> - 2013-04-19 12:32 +0200
Re: subprocess.call jt@toerring.de (Jens Thoms Toerring) - 2013-04-19 14:43 +0000
| From | Ombongi Moraa Fe <moraa.lovetakes2@gmail.com> |
|---|---|
| Date | 2013-04-19 12:56 +0300 |
| Subject | RE: subprocess.call |
| Message-ID | <mailman.819.1366365414.3114.python-list@python.org> |
[Multipart message — attachments visible in raw view] — view raw
Hi Team, In my python script, I have this: command="lynx -dump 'phpscript?param1=%s¶m2=%s¶m3=%s¶m4=%s¶m5=%s'"%(value1,value2,value3,value4) result=subprocess.call(command,shell=True) print 'xml message' However, the response from running the php script is also printed on output screen. I don't want this output. How can i ensure that only the last print 'xml response' is returned? Saludos Ombongi Moraa Faith
[toc] | [next] | [standalone]
| From | Mau C <nobody@hotmail.com> |
|---|---|
| Date | 2013-04-19 12:32 +0200 |
| Message-ID | <51711d28$0$1374$4fafbaef@reader2.news.tin.it> |
| In reply to | #43893 |
Il 19/04/2013 11:56, Ombongi Moraa Fe ha scritto: > Hi Team, > > In my python script, I have this: > > command="lynx -dump > 'phpscript?param1=%s¶m2=%s¶m3=%s¶m4=%s¶m5=%s'"%(value1,value2,value3,value4) http://docs.python.org/2/library/subprocess.html#module-subprocess You should set the properly values for stdou and stderr. Under UNIX, '/dev/null' worked out fine for me, when 'None' didn't. M.
[toc] | [prev] | [next] | [standalone]
| From | jt@toerring.de (Jens Thoms Toerring) |
|---|---|
| Date | 2013-04-19 14:43 +0000 |
| Message-ID | <atd3fpF7rb7U1@mid.uni-berlin.de> |
| In reply to | #43893 |
Ombongi Moraa Fe <moraa.lovetakes2@gmail.com> wrote:
> [-- text/plain, encoding 7bit, charset: ISO-8859-1, 19 lines --]
> In my python script, I have this:
> command="lynx -dump
> 'phpscript?param1=%s¶m2=%s¶m3=%s¶m4=%s¶m5=%s'"%(value1,value2,value3,value4)
> result=subprocess.call(command,shell=True)
> print 'xml message'
> However, the response from running the php script is also printed on output
> screen. I don't want this output.
> How can i ensure that only the last print 'xml response' is returned?
You mean is printed out? Use subprocess.Popen() and redirect
stdout to a pipe, similar to this:
p = subprocess.Popen(command, stdout=subprocess.PIPE)
r = p.communicate()
print r[0] # This is the output (to stdout)
The return value of the Popen objects communicate() method is
a tuple with two elements, first contains what got written to
stdout (if redirected to a pipe, otherwise Nome), the second
what went to stderr (again if redirected to a pipe). If you
also redirect stdin then you can pass what you want to send
to the process spawned via Popen() as an argument to commu-
nicate().
BTW, according to the dicumentation you should split the
command line into its componenents and pass that as a list
to the call() or Popen() subprocess methods, so it would
seem to reasonable to use e.g.
command = [ 'lynx', '-dump',
( "'phpscript?param1={0}¶m2={1}¶m3={2}"
"¶m4={3}¶m5={4}'" )
.format( value1, value2, value3, value4, value5 ) ]
Note that there was one value for creating the string to be
passed to lynx was mising.
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web