Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'example:': 0.03; 'argument': 0.05; 'subject:Python': 0.06; 'assignment': 0.07; 'advance': 0.07; 'executed': 0.09; 'tmp': 0.09; 'python': 0.11; '"%s"': 0.16; 'docs.': 0.16; 'doing:': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'skip:f 30': 0.19; 'command': 0.22; 'memory': 0.22; 'email addr:gmail.com>': 0.22; 'this?': 0.23; 'pass': 0.26; 'header:In-Reply-To:1': 0.27; 'skip:- 40': 0.29; '8bit%:3': 0.30; 'went': 0.31; 'extract': 0.31; 'figure': 0.32; 'open': 0.33; 'skip:s 30': 0.35; 'tool': 0.35; 'received:google.com': 0.35; 'doing': 0.36; 'method': 0.36; 'thanks': 0.36; 'so,': 0.37; 'skip:- 20': 0.37; 'message-id:@gmail.com': 0.38; '8bit%:4': 0.38; 'feed': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; '8bit%:6': 0.40; 'how': 0.40; 'skip:u 10': 0.60; 'header:Message-Id:1': 0.63; 'charset:windows-1252': 0.65; '2014,': 0.84; 'skip:\x91 10': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:content-type:message-id:mime-version:subject:date:references :to:in-reply-to; bh=n4RtGORHf/gvt2xfdJdrS9ujbp8oS59gcXKDktizHww=; b=Wo3HEfvItUBErJSAOTvi/AvUXnjgGXDfpK+I3MJaDafip2zWTxfrpU3PjFJGfF8xsz n9ZxSWF8blDomsz9kcQKMIcMzbB6QAF6kGrda7CTBiVCWfarQ4YCb2bVJ9+BRIwosvSs GlrudrYRS5CWDYmEEO2vlDocnRApFoQN10/yAe5eUI3N+6wVYydq50gDqVZ9IxZUqJKQ 3OTIUNPCopBUys4sIIWFgrw1sCUnrqKBMepXTdw0D7CEMBtKhWQfSGqPXp3/y00qTqsl e/SqMRi2f0FNUaRAkUyMMWu4+2YLPmbAH2u8Ffaoj129GLTE/7bMjJqNGqH41XT5w66e YAbg== X-Received: by 10.66.148.98 with SMTP id tr2mr5453846pab.33.1401338906395; Wed, 28 May 2014 21:48:26 -0700 (PDT) From: Satish Muthali Content-Type: multipart/alternative; boundary="Apple-Mail=_B74A1735-E1A2-4E5C-AA24-DB4F56706589" Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.2\)) Subject: Re: passing Python assignment value to shell Date: Wed, 28 May 2014 21:48:24 -0700 References: To: python-list@python.org In-Reply-To: X-Mailer: Apple Mail (2.1878.2) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 133 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1401338909 news.xs4all.nl 2872 [2001:888:2000:d::a6]:47687 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:72216 --Apple-Mail=_B74A1735-E1A2-4E5C-AA24-DB4F56706589 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=windows-1252 Hello Experts, I was able to figure this out after spending time reading the Python = help docs. This is what I went about doing: > reecalc =3D [s.split() for s in os.Popen("free = -ht").read().splitlines()] > freecalc_total =3D freecalc[4] > freecalc_total =3D freecalc_total[3] > freecalc_total =3D freecalc_total.translate(None, 'M=92) tmp =3D "%s" % freecalc_total command =3D "stressapptest -M %s -s 20" % tmp p =3D subprocess.Popen(command, shell=3DTrue, stdout=3Dsubprocess.PIPE,= stderr=3Dsubprocess.PIPE).communicate()[0] =85 =85 ... Please let me know if this is the optimal method to achieve in order to = pass the assignment value to shell. I am open to suggestions or a better = way of implementation/logic. Thanks again Satish On May 28, 2014, at 1:16 PM, Satish Muthali = wrote: > Hello Experts, >=20 > I am trying to extract the available userspace+swap memory and then = want to feed this value as an argument to a tool that is executed in the = shell. >=20 > so, this is what I have so far: >=20 > reecalc =3D [s.split() for s in os.Popen("free = -ht").read().splitlines()] > freecalc_total =3D freecalc[4] > freecalc_total =3D freecalc_total[3] > freecalc_total =3D freecalc_total.translate(None, 'M=92) >=20 > Now I want to feed the value for =91freecalc_total=92 as an argument = to a command executed by the shell. >=20 > For example: >=20 > devnull =3D open(os.devnull, =93w=94) > runCommand =3D subprocess.call([=93stressapptest=94, =93=94, = =9320=94],stdout=3Ddevnull,stderr=3Dsubprocess.STDOUT) > devnull.close() >=20 > How do I go about doing this? >=20 > Many thanks in advance >=20 > -Satish --Apple-Mail=_B74A1735-E1A2-4E5C-AA24-DB4F56706589 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=windows-1252 Hello = Experts,

I was able to figure this out after spending = time reading the Python help docs.

This is what = I went about doing:


reecalc =3D [s.split() for s in os.Popen("free = -ht").read().splitlines()]
freecalc_total =3D = freecalc[4]
freecalc_total =3D = freecalc_total[3]
freecalc_total =3D freecalc_total.translate(None, = 'M=92)
   tmp =3D "%s" % = freecalc_total
  command =3D "stressapptest -M %s -s 20" % = tmp
  p =3D = subprocess.Popen(command, shell=3DTrue,  stdout=3Dsubprocess.PIPE, = stderr=3Dsubprocess.PIPE).communicate()[0]
=85
=85
...

Please = let me know if this is the optimal method to achieve in order to pass = the assignment value to shell. I am open to suggestions or a better way = of implementation/logic.

Thanks = again

Satish

On May 28, = 2014, at 1:16 PM, Satish Muthali <satish.muthali@gmail.com> = wrote:

Hello = Experts,

I am trying to extract the available = userspace+swap memory and then want to feed this value as an argument to = a tool that is executed in the shell.

so, this = is what I have so far:

reecalc =3D = [s.split() for s in os.Popen("free = -ht").read().splitlines()]
freecalc_total =3D = freecalc[4]
freecalc_total =3D = freecalc_total[3]
freecalc_total =3D = freecalc_total.translate(None, = 'M=92)

Now I want = to feed the value for =91freecalc_total=92 as an argument to a = command executed by the shell.

For = example:

devnull =3D open(os.devnull, = =93w=94)
runCommand =3D subprocess.call([=93stressapptest=94, = =93<I want to pass the value of freecalc_total here>=94, = =9320=94],stdout=3Ddevnull,stderr=3Dsubprocess.STDOUT)
devnull.c= lose()

How do I go about  doing = this?

Many thanks in = advance

-Satish
= --Apple-Mail=_B74A1735-E1A2-4E5C-AA24-DB4F56706589--