Hmm, I think that perhaps you don't understand what unmarshalling data
does for you. No parsing of strings is ever needed. The act of
marshalling takes a data structure and converts it into a string-based
representation. The act of unmarshalling reverses this and converts the
string-based representation back into a data structure. So, when you
unmarshall data you then have a marshalling context that you can call its
getRootObject method to get the root object which can be a list, a map, or
a string, represented in objects for the language that you are using. So,
if you're using Python to submit a PROCESS START WAIT RETURNSTDOUT request
whose result is as you described, you can access the stdout file's "data"
field directly. For example, here's a Python program that submits a
PROCESS START RETURNSTDOUT WAIT request and that unmarshalls the result
and gets the root object (a Python dictionary, aka map) and assigned it to
processMap. Then, it checks the process's rc to see if it completed
successfully. If the rc is "0", then it gets the 'fileList' entry from
the processMap (a Python list) which contains a list of files returned by
the process. In this case, this list contains one entry for stdout where
the entry in the list is a map with keys 'rc' and 'data'. So, then it
can direct access the stdout file data from the 'fileList' entry in the
processMap as follows: processMap['fileList'][0]['data']
from PySTAF import *
import sys
try:
handle = STAFHandle("Lang/Python/Test/Basic")
except STAFException, e:
print "Error registering with STAF, RC: %d" % e.rc
sys.exit(e.rc)
print "Using handle %d" % handle.handle
machine = "local"
command = "df"
request = "START SHELL COMMAND %s RETURNSTDOUT STDERRTOSTDOUT WAIT" %
(wrapData(command))
result = handle.submit(machine, "PROCESS", request)
if (result.rc != STAFResult.Ok):
print "Error: STAF %s PROCESS %s, RC: %d, Result: %s" % \
(machine, request, result.rc, result.result)
sys.exit(result.rc)
mc = unmarshall(result.result)
processMap = mc.getRootObject()
if processMap['rc'] != "0":
print "Command %s failed with RC: " % (command, processMap['rc'])
print formatObject(processMap, mc)
sys.exit(1)
print "Command %s completed successfully." % (command)
print "\nFormatObject: %s" % (formatObject(processMap, mc))
print "\nStdout data:\n%s" % (processMap['fileList'][0]['data'])
handle.unregister()
sys.exit(0)
Here's the output I get from running this Python program:
C:\dev\sf\src\staf\lang\python>python ProcessStart.py
Using handle 107
Command df completed successfully.
FormatObject:
{
Return Code: 0
Key : <None>
Files : [
{
Return Code: 0
Data : Filesystem 1k-blocks Used Available Use%
Mounted on
C:\cygwin\bin 58583168 50219040 8364128 86% /usr/bin
C:\cygwin\lib 58583168 50219040 8364128 86% /usr/lib
C:\cygwin 58583168 50219040 8364128 86% /
c: 58583168 50219040 8364128 86% /cygdrive/c
t: 124479620 22709448 101770172 19% /cygdrive/t
}
]
}
STDOUT Data:
Filesystem 1k-blocks Used Available Use% Mounted on
C:\cygwin\bin 58583168 50219040 8364128 86% /usr/bin
C:\cygwin\lib 58583168 50219040 8364128 86% /usr/lib
C:\cygwin 58583168 50219040 8364128 86% /
c: 58583168 50219040 8364128 86% /cygdrive/c
t: 124479620 22709448 101770172 19% /cygdrive/t
--------------------------------------------------------------
Sharon Lucas
IBM Austin, [EMAIL PROTECTED]
(512) 838-8347 or Tieline 678-8347
George Flaherty <[EMAIL PROTECTED]>
Sent by: [EMAIL PROTECTED]
08/14/2008 01:05 PM
To
"staf-users@lists.sourceforge.net" <staf-users@lists.sourceforge.net>
cc
Subject
[staf-users] Parsing Verbose Output into maps elements?
I have some process requests that I fire on different systems and I need
to parse out some of the results. Since the result is in to be Verbose
Formatted (after I unmarshall it), I am wondering if there is some way to
extract just the data portion as a map or some other data structure? Or am
I slaved to parsing the string with python?
For example I want to extract out the ?DATA? portion of the following:
{
Return Code: 0
Key : <None>
Files : [
{
Return Code: 0
Data : mmx2 270750 438492 1 13:27:56 pts/1 0:11
/foo/MEServer
autousr 438706 336088 0 13:59:54 - 0:00 grep MEServer
}
]
}
thanks
-george
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's
challenge
Build the coolest Linux based applications with Moblin SDK & win great
prizes
Grand prize is a trip for two to an Open Source event anywhere in the
world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users