passing Python assignment value to shell

S

Satish Muthali

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
 
J

John Gordon

In said:
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>'], stdout=devnull,stderr=subprocess.STDOUT)
devnull.close()

I think you can just include freecalc_total directly as part of the
argument list, like this:

runCommand = subprocess.call(['stressapptest', freecalc_total],
stdout=devnull, stderr=subprocess.STDOUT)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top