How to get the output from os.system() into a variable?

A

alexLIGO

Hi,

I would like to execute some command in python on the bash, e.g.

os.system('globus-job-run mike4.cct.lsu.edu/jobmanager-pbs -l
/bin/date')

and want the result of the output in a vector, so something like:

result=python_command(' command_on_the_bash ')

Is that possible? And how to do that?

Thanks
Alexander Dietz
 
L

Laszlo Zsolt Nagy

alexLIGO said:
Hi,

I would like to execute some command in python on the bash, e.g.

os.system('globus-job-run mike4.cct.lsu.edu/jobmanager-pbs -l
/bin/date')

and want the result of the output in a vector, so something like:

result=python_command(' command_on_the_bash ')

Is that possible? And how to do that?
You can use one of these:

the subprocess module: http://docs.python.org/lib/module-subprocess.html
the popen2 module: http://docs.python.org/lib/module-popen2.html
popen and spawn variants from the os module:
http://docs.python.org/lib/os-process.html
pexpect (it is not in the standard library):
http://pexpect.sourceforge.net/

I believe that if you do not need the extended functionality of
"pexpect", then you should start with the "subprocess" module.
It is the newest.

Les
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top