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


Groups > comp.lang.python > #72216

Re: passing Python assignment value to shell

From Satish Muthali <satish.muthali@gmail.com>
Subject Re: passing Python assignment value to shell
Date 2014-05-28 21:48 -0700
References <BDCE7625-97B0-46D8-B49C-56597752F6D9@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.10436.1401338909.18130.python-list@python.org> (permalink)

Show all headers | View raw


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

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 = [s.split() for s in os.Popen("free -ht").read().splitlines()]
> freecalc_total = freecalc[4]
> freecalc_total = freecalc_total[3]
> freecalc_total = freecalc_total.translate(None, 'M’)

   tmp = "%s" % freecalc_total
  command = "stressapptest -M %s -s 20" % tmp
  p = subprocess.Popen(command, shell=True,  stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]
…
…
...

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 = [s.split() for s in os.Popen("free -ht").read().splitlines()]
> freecalc_total = freecalc[4]
> freecalc_total = freecalc_total[3]
> freecalc_total = freecalc_total.translate(None, 'M’)
> 
> Now I want to feed the value for ‘freecalc_total’ as an argument to a command executed by the shell.
> 
> For example:
> 
> devnull = open(os.devnull, “w”)
> runCommand = subprocess.call([“stressapptest”, “<I want to pass the value of freecalc_total here>”, “20”],stdout=devnull,stderr=subprocess.STDOUT)
> devnull.close()
> 
> How do I go about  doing this?
> 
> Many thanks in advance
> 
> -Satish

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


Thread

Re: passing Python assignment value to shell Satish Muthali <satish.muthali@gmail.com> - 2014-05-28 21:48 -0700

csiph-web