473,289 Members | 2,106 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

capturing output of command line in an array

Hi

I am trying to execute a command using os.system. this command lists
the number of nodes alive in a cluster. I would like to capture the
output in list/array in python. IS it possible.?/

Here is my command
gstat -a
node13 2 ( 0/ 56) [ 0.00, 0.00, 0.00] [ 0.0, 0.0,
0.1, 99.9, 0.0] OFF
node12 2 ( 1/ 63) [ 0.99, 0.97, 0.91] [ 46.6, 0.0,
3.7, 49.8, 0.0] OFF
node8 2 ( 1/ 59) [ 0.99, 0.97, 0.91] [ 47.5, 0.0,
2.8, 49.7, 0.0] OFF
node2 2 ( 1/ 59) [ 0.99, 0.97, 0.91] [ 46.6, 0.0,
3.7, 49.7, 0.0] OFF
node1 2 ( 1/ 59) [ 0.99, 0.97, 0.91] [ 46.6, 0.0,
3.7, 49.7, 0.0] OFF
node7 2 ( 1/ 58) [ 0.99, 0.97, 0.91] [ 49.8, 0.0,
0.6, 49.7, 0.0] OFF
node11 2 ( 1/ 59) [ 0.99, 0.97, 0.91] [ 46.6, 0.0,
3.8, 49.6, 0.0] OFF
node4 2 ( 1/ 59) [ 1.00, 1.00, 0.93] [ 46.6, 0.0,
3.7, 49.7, 0.0] OFF
node10 2 ( 1/ 59) [ 1.00, 1.00, 0.94] [ 46.7, 0.0,
3.7, 49.7, 0.0] OFF
node5 2 ( 1/ 59) [ 1.00, 1.00, 0.92] [ 49.8, 0.0,
0.4, 49.7, 0.0] OFF
node6 2 ( 1/ 59) [ 1.00, 1.00, 0.94] [ 49.5, 0.0,
0.9, 49.7, 0.0] OFF

I would like to have an array where each element contains the nodes

for example
a=[node13,node12,node2,node8,node1,node7,node 11]

any help would be appreciated

thanks

Oct 31 '07 #1
4 5939

On Oct 31, 2007, at 11:01 AM, am******@gmail.com wrote:
I am trying to execute a command using os.system. this command lists
the number of nodes alive in a cluster. I would like to capture the
output in list/array in python. IS it possible.?/

Here is my command
gstat -a
node13 2 ( 0/ 56) [ 0.00, 0.00, 0.00] [ 0.0, 0.0,
0.1, 99.9, 0.0] OFF
node12 2 ( 1/ 63) [ 0.99, 0.97, 0.91] [ 46.6, 0.0,
3.7, 49.8, 0.0] OFF
node8 2 ( 1/ 59) [ 0.99, 0.97, 0.91] [ 47.5, 0.0,
2.8, 49.7, 0.0] OFF
node2 2 ( 1/ 59) [ 0.99, 0.97, 0.91] [ 46.6, 0.0,
3.7, 49.7, 0.0] OFF
node1 2 ( 1/ 59) [ 0.99, 0.97, 0.91] [ 46.6, 0.0,
3.7, 49.7, 0.0] OFF
node7 2 ( 1/ 58) [ 0.99, 0.97, 0.91] [ 49.8, 0.0,
0.6, 49.7, 0.0] OFF
node11 2 ( 1/ 59) [ 0.99, 0.97, 0.91] [ 46.6, 0.0,
3.8, 49.6, 0.0] OFF
node4 2 ( 1/ 59) [ 1.00, 1.00, 0.93] [ 46.6, 0.0,
3.7, 49.7, 0.0] OFF
node10 2 ( 1/ 59) [ 1.00, 1.00, 0.94] [ 46.7, 0.0,
3.7, 49.7, 0.0] OFF
node5 2 ( 1/ 59) [ 1.00, 1.00, 0.92] [ 49.8, 0.0,
0.4, 49.7, 0.0] OFF
node6 2 ( 1/ 59) [ 1.00, 1.00, 0.94] [ 49.5, 0.0,
0.9, 49.7, 0.0] OFF

I would like to have an array where each element contains the nodes

for example
a=[node13,node12,node2,node8,node1,node7,node 11]

any help would be appreciated
You might try os.popen to read in the output of your command.

It would be helpful to have more information about what you'd like to
do with your list. Do you just want to put the text of the
individual node lines from gstat into the list? If so, os.popen
should work for you. Or do you need to parse the lines and store
them in, say dictionaries? Tuples? If you need to parse it, you
could use module re, or even just string methods, depending on what
you're trying to do . . . .

HTH,

---
Lee Capps
Technology Specialist
CTE Resource Center
lc****@cteresource.org

Oct 31 '07 #2
Thanks Lee
I am looking to just get the node name from that info.
I dont need all other info
so my list would be just
alist=[node13,node12,node8,node1 ....]
is it possible??

On Oct 31, 9:44 am, Lee Capps <lca...@cteresource.orgwrote:
On Oct 31, 2007, at 11:01 AM, amjad...@gmail.com wrote:
I am trying to execute a command using os.system. this command lists
the number of nodes alive in a cluster. I would like to capture the
output in list/array in python. IS it possible.?/
Here is my command
gstat -a
node13 2 ( 0/ 56) [ 0.00, 0.00, 0.00] [ 0.0, 0.0,
0.1, 99.9, 0.0] OFF
node12 2 ( 1/ 63) [ 0.99, 0.97, 0.91] [ 46.6, 0.0,
3.7, 49.8, 0.0] OFF
node8 2 ( 1/ 59) [ 0.99, 0.97, 0.91] [ 47.5, 0.0,
2.8, 49.7, 0.0] OFF
node2 2 ( 1/ 59) [ 0.99, 0.97, 0.91] [ 46.6, 0.0,
3.7, 49.7, 0.0] OFF
node1 2 ( 1/ 59) [ 0.99, 0.97, 0.91] [ 46.6, 0.0,
3.7, 49.7, 0.0] OFF
node7 2 ( 1/ 58) [ 0.99, 0.97, 0.91] [ 49.8, 0.0,
0.6, 49.7, 0.0] OFF
node11 2 ( 1/ 59) [ 0.99, 0.97, 0.91] [ 46.6, 0.0,
3.8, 49.6, 0.0] OFF
node4 2 ( 1/ 59) [ 1.00, 1.00, 0.93] [ 46.6, 0.0,
3.7, 49.7, 0.0] OFF
node10 2 ( 1/ 59) [ 1.00, 1.00, 0.94] [ 46.7, 0.0,
3.7, 49.7, 0.0] OFF
node5 2 ( 1/ 59) [ 1.00, 1.00, 0.92] [ 49.8, 0.0,
0.4, 49.7, 0.0] OFF
node6 2 ( 1/ 59) [ 1.00, 1.00, 0.94] [ 49.5, 0.0,
0.9, 49.7, 0.0] OFF
I would like to have an array where each element contains the nodes
for example
a=[node13,node12,node2,node8,node1,node7,node 11]
any help would be appreciated

You might try os.popen to read in the output of your command.

It would be helpful to have more information about what you'd like to
do with your list. Do you just want to put the text of the
individual node lines from gstat into the list? If so, os.popen
should work for you. Or do you need to parse the lines and store
them in, say dictionaries? Tuples? If you need to parse it, you
could use module re, or even just string methods, depending on what
you're trying to do . . . .

HTH,

---
Lee Capps
Technology Specialist
CTE Resource Center
lca...@cteresource.org

Oct 31 '07 #3
En Wed, 31 Oct 2007 19:20:56 -0300, <am******@gmail.comescribió:
I am looking to just get the node name from that info.
I dont need all other info
so my list would be just
alist=[node13,node12,node8,node1 ....]
is it possible??
node13 2 ( 0/ 56) [ 0.00, 0.00, 0.00] [ 0.0, 0.0,
0.1, 99.9, 0.0] OFF
node12 2 ( 1/ 63) [ 0.99, 0.97, 0.91] [ 46.6, 0.0,
3.7, 49.8, 0.0] OFF
node8 2 ( 1/ 59) [ 0.99, 0.97, 0.91] [ 47.5, 0.0,
2.8, 49.7, 0.0] OFF
Try this:

import subprocess
p = subprocess.Popen( ["your","command","+args"], stdout=subprocess.PIPE)
lines = p.stdout.readlines()
p.wait()

If you are only interested in the first word in each line, you may replace
the lines = ... above with this:

nodes = [line.split(' ', 1)[0] for line in p.stdout]

--
Gabriel Genellina

Nov 1 '07 #4
thanks Lee,
I would just like to get the "node" in that list.
so it would be something like this
alist=[node13,node12,node8,node2,node1.....]
I dont want the whole info
is it possible??
On Oct 31, 9:44 am, Lee Capps <lca...@cteresource.orgwrote:
On Oct 31, 2007, at 11:01 AM, amjad...@gmail.com wrote:
I am trying to execute a command using os.system. this command lists
the number of nodes alive in a cluster. I would like to capture the
output in list/array in python. IS it possible.?/
Here is my command
gstat -a
node13 2 ( 0/ 56) [ 0.00, 0.00, 0.00] [ 0.0, 0.0,
0.1, 99.9, 0.0] OFF
node12 2 ( 1/ 63) [ 0.99, 0.97, 0.91] [ 46.6, 0.0,
3.7, 49.8, 0.0] OFF
node8 2 ( 1/ 59) [ 0.99, 0.97, 0.91] [ 47.5, 0.0,
2.8, 49.7, 0.0] OFF
node2 2 ( 1/ 59) [ 0.99, 0.97, 0.91] [ 46.6, 0.0,
3.7, 49.7, 0.0] OFF
node1 2 ( 1/ 59) [ 0.99, 0.97, 0.91] [ 46.6, 0.0,
3.7, 49.7, 0.0] OFF
node7 2 ( 1/ 58) [ 0.99, 0.97, 0.91] [ 49.8, 0.0,
0.6, 49.7, 0.0] OFF
node11 2 ( 1/ 59) [ 0.99, 0.97, 0.91] [ 46.6, 0.0,
3.8, 49.6, 0.0] OFF
node4 2 ( 1/ 59) [ 1.00, 1.00, 0.93] [ 46.6, 0.0,
3.7, 49.7, 0.0] OFF
node10 2 ( 1/ 59) [ 1.00, 1.00, 0.94] [ 46.7, 0.0,
3.7, 49.7, 0.0] OFF
node5 2 ( 1/ 59) [ 1.00, 1.00, 0.92] [ 49.8, 0.0,
0.4, 49.7, 0.0] OFF
node6 2 ( 1/ 59) [ 1.00, 1.00, 0.94] [ 49.5, 0.0,
0.9, 49.7, 0.0] OFF
I would like to have an array where each element contains the nodes
for example
a=[node13,node12,node2,node8,node1,node7,node 11]
any help would be appreciated

You might try os.popen to read in the output of your command.

It would be helpful to have more information about what you'd like to
do with your list. Do you just want to put the text of the
individual node lines from gstat into the list? If so, os.popen
should work for you. Or do you need to parse the lines and store
them in, say dictionaries? Tuples? If you need to parse it, you
could use module re, or even just string methods, depending on what
you're trying to do . . . .

HTH,

---
Lee Capps
Technology Specialist
CTE Resource Center
lca...@cteresource.org

Nov 1 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: jerrygarciuh | last post by:
Hello, I have a client who has decided to output the OO PHP/mySQL site I have made for them onto a cd. I realize that $html = include('somefile.php'); gets 1 for success as its return value....
4
by: Mark Wilson CPU | last post by:
This must be easy, but I'm missing something... I want to execute a Perl script, and capture ALL its output into a PHP variable. Here are my 2 files: -------------------------------------...
5
by: Moosebumps | last post by:
I have a large set of Python scripts that interface with command line utilities (primarily Perforce). I am currently capturing ALL the text output in order to get results and such. I am using the...
1
by: Oz | last post by:
This is long. Bear with me, as I will really go through all the convoluted stuff that shows there is a problem with streams (at least when used to redirect stdout). The basic idea is that my...
1
by: Manish | last post by:
I have the following code in a script -------------------------------------------------------------------------------------------------------------------------------- foreach($serverlist as...
6
by: Ed Leafe | last post by:
I've been approached by a local business that has been advised that they need to start capturing and archiving their instant messaging in order to comply with Sarbanes-Oxley. The company is largely...
0
by: Buglish | last post by:
Hi, Task : -Capture a HTML table with use of regular expression from a text string buffer(entire document). –Pass it to another function to create a multi dimension array out of it. - Pass it...
0
by: ptek | last post by:
Hi, I'm using Vstudio 2005 and I did a Windows Application project where I also want to read arguments from command line and output some text when appropriate (for example, typing the correct...
2
by: jdbartlett | last post by:
I'm trying to capture output from a command line utility (XMLSec), but only get an empty result. If I call the script from the command line, I see XMLSec's output, but I can't seem to capture it!...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.