hi,

can you please help me with a sample python code to retrive data from command prompt which appears after execution of some commanad

for eg: ./vershion.sh
gives ouput as

version: 7.0.0.9
type : NAS

thanks in advance

You can use the Command class in this code snippet. You would write

com = Command("./vershion.sh").run()
if com.failed:
    print(com.error)
else:
    print(com.output)

thanks a lot

this code works good but i need only some of the fields in output like version,type,etc,.

can you please help me with text parsing of required fields.

Well, you can use split()

s = """
version: 7.0.0.9
type : NAS
"""

lines = s.strip().split("\n")
lines = [tuple(x.strip() for x in y.split(":")) for y in lines]

print(lines)

""" my output -->
[('version', '7.0.0.9'), ('type', 'NAS')]
"""

thank you for the code

here we assumed to get all the parameters in the output.
if there are more number of parameters, out of which we need to print version and type only

can you please help with the code to get out this

if there are more number of parameters, out of which we need to print version and type only

can you please help with the code to get out this

You have to post an example of how the other parameters look.
There are many ways to do this,if data is unformatet/changing regex can be and option.

import re

data = '''\
abc : 123
version: 7.0.0.9
type : NAS
ggg.2 : 4444
version: 8
type : FOO
hg.1234: test'''

result = re.findall(r"version.*|type.*", data)
print result
print zip(*[iter(result)]*2)
print [tuple(x.strip() for x in y.split(":")) for y in result] 

"""Output-->
['version: 7.0.0.9', 'type : NAS', 'version: 8', 'type : FOO']
[('version: 7.0.0.9', 'type : NAS'), ('version: 8', 'type : FOO')]
[('version', '7.0.0.9'), ('type', 'NAS'), ('version', '8'), ('type', 'FOO')]
"""

here is the screen shot

Product List
--------------------------------------------------------------------------------




WXSI                      installed




WXDOPI                    installed
NDI                       installed

Installed Product
--------------------------------------------------------------------------------
Name                     eXtreme Scale
Version                  8.0.0.0
ID                       WXS
Build Level              cd11
Build Date               6/11/11




Architecture             AMD (64 bit)

Installation
--------------------------------------------------------------------------------
Product Directory        /abcd
Version Directory        /abcd/properties/version
DTD Directory            /abcd/properties/version/dtd
Log Directory            /abcd/logs
Backup Directory         /abcd/properties/version/nif/backup
TMP Directory            /tmp

from this i need version,id,architecture,Product Directory

please help me

You must try some python code. We already gave 2 methods, where is your python code to extract the data ?

i had ran your script but it is not giving corrct results.

is there any other way to get required fields, can it is possible with awk command

if possible give me sample code

sir can u please help me out, am new to python

Who are you?
venkaaaaat, vankaat or venkaat?

Oooops!

hello sir,

i have doubt that how to redirect the ouput text of a command (while working on unix cmd prompt) to file using python.please help me with sample code.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.