See example 3 in section "4.1.2.2 STAF::STAFHandle::submit" in the STAF 
Perl User's Guide at 
http://staf.sourceforge.net/current/STAFPerl.htm#Header_SubmitOO.

It shows how to access the stdout data from the unmarshalled result object 
(e.g. in $cmdResult->{resultObj} ) returned by a PROCESS START request 
that returns a file containing stdout/stderr data and how to access the 
file data.

Note that you do not have to unmarshall the result from any STAF command 
yourself as STAF automatically unmarshalls the result and makes it 
available in the resultObj field of the result.  For example: . 
$cmdResult->{resultObj}

Also, you should always first check if the PROCESS START request worked or 
not by checking if the $cmdResult->{rc} is 0 because if it didn't, then 
the $cmdResult->{resultObj} will contain a string containing the error 
message (instead of a map containing the result from the PROCESS START 
request.

In your case, you are returning stdout and stderr as 2 separate files 
(instead of redirecting stderr to stdout using the STDERRTOSTDOUT option 
such that only 1 file is returned in example 3).  So, to access the data 
in the returned stdout file, you specify to access the first file in the 
fileList (like in the example) as follows: 

my $stdoutData = $cmdResult->{resultObj}->{fileList}[0]{data};

To access the data in the returned stderr file, you specify to access the 
second file in the fileList as follows:

my $stderrData = $cmdResult->{resultObj}->{fileList}[1]{data};

Here's example 3 from the STAF Perl User's Guide that you should look at 
for guidance:

3. This example submits a request to the PROCESS service to run a command 
on a machine and to wait for the command to complete. It shows the use of 
the STAFResult class when submitting a request to a STAF service using a 
handle that has auto-unmarshalling results enabled. The request returns 
marshalled data whose root object is a map that contains keys like 'rc' 
and 'fileList'. The value for 'fileList' is a list of the returned files. 
Each entry in the list consists of a map that contains keys 'rc' and 
'data'. In our PROCESS START request, we returned one file, stdout, and 
returned stderr to this same file. (Note that the STAF User's Guide 
defines the results for each request submitted to an internal STAF 
service.) 

# Submit a PROCESS START request and wait for it to complete

my $command = 'dir {STAF/Config/STAFRoot}';
my $request = "START SHELL COMMAND ".STAF::WrapData($command).
              " RETURNSTDOUT STDERRTOSTDOUT WAIT";

print "\nSTAF local PROCESS $request\n";

my $result = $handle->submit("local", "PROCESS", $request);

if ($result->{rc} != $STAF::kOk) {
    print "Error on STAF local PROCESS $request\n";
    print "Expected RC: 0\n";
    print "Received RC: $result->{rc}, Result: $result->{result}\n";
    exit $result->{rc}; 
}

# The result is a marshalling context whose root object is a
# map containing keys 'rc', and 'fileList'.  The value for
# 'fileList' is a list of the returned files.  Each entry in the
# list consists of a map that contains keys 'rc' and 'data'.
# In our PROCESS START request, we returned one file, stdout (and
# returned stderr to this same file).

# Get process RC

my $processRC = $result->{resultObj}->{rc};

# Verify that the rc is 0 for returning data for the Stdout file 

my $stdoutRC = $result->{resultObj}->{fileList}[0]{rc};

if ($stdoutRC != $STAF::kOk) {
    print "Error on retrieving process's stdout data.\n";
    print "Expected RC: 0\n";
    print "Received RC: $stdoutRC\n";
    exit $stdoutRC; 
}

# Print the data in the stdout file created by the process

my $stdoutData = $result->{resultObj}->{fileList}[0]{data};

print "\nProcess Stdout File Contains:\n";
print "$stdoutData\n";

# Verify that the process rc is 0

if ($processRC != $STAF::kOk) {
    print "Process RC: $processRC\n";
    print "Expected Process RC: 0\n";
    exit $processRC;
}

This example could print the following when run: 
STAF local PROCESS START SHELL COMMAND :26:dir {STAF/Config/STAFRoot} 
RETURNSTDOUT STDERRTOSTDOUT WAIT

Process Stdout File Contains:
 Volume in drive C has no label.
 Volume Serial Number is B0B7-F95A

 Directory of C:\STAF

01/26/2006  02:56p      <DIR>          .
01/26/2006  02:56p      <DIR>          ..
01/26/2006  02:56p      <DIR>          lib
01/26/2006  02:56p      <DIR>          codepage
01/26/2006  02:56p      <DIR>          samples
01/26/2006  02:57p      <DIR>          include
01/26/2006  02:57p      <DIR>          bin
02/25/2008  01:30p              17,029 LICENSE.htm
01/26/2006  03:04p      <DIR>          docs
01/26/2006  03:11p      <DIR>          data
02/12/2008  05:05p                  25 STAFReg.inf
06/05/2008  10:17a               8,729 NOTICES.htm
06/24/2008  04:34p                  77 install.properties
               4 File(s)         72,601 bytes
               9 Dir(s)   8,199,012,352 bytes free


--------------------------------------------------------------
Sharon Lucas
IBM Austin,   luc...@us.ibm.com
(512) 286-7313 or Tieline 363-7313




From:   <sanjeev.lohc...@emc.com>
To:     Sharon Lucas/Austin/IBM@IBMUS
Cc:     <staf-users@lists.sourceforge.net>
Date:   04/18/2011 01:29 AM
Subject:        RE: [staf-users] How to pass prams to process request 
using submit2



Hi Sharon,
 
Thanx that really helped in progressing.
 
I have one more query.  I am unmarshalling the resultcontext, but it is 
not returning me the actual result.  Here is my code:
 
$queryCmd=&Install::Linux::queryClient($package,$osPlatform,1);
 
                    my $request="start shell command 
".STAF::WrapData($queryCmd)." returnstderr returnstdout wait";
                    print "Request : $request\n";
                    $cmdResult = 
$fHandle->submit2($STAF::STAFHandle::kReqSync,"$machineName", "process", 
$request);
                    my 
$mc=STAF::STAFUnmarshall($cmdResult->{resultContext});
                    my $rootObject=$mc->getRootObject();
                    print "Formated Output :\n", $mc->formatObject(),"\n";
                    my $itemMap;
                    foreach $itemMap (@{$rootObject->{fileList}}) {
                                    print "Data : $itemMap->{data}\n";
                    }
 
The Formated output :
{
  Return Code: 0
  Key        : <None>
  Files      : [
    {
      Return Code: 0
      Data       : AvamarClient-6.0.100-580
 
    }
    {
      Return Code: 0
      Data       : 
    }
  ]
}
 
But in the last loop when I am trying to get the value of data it is not 
returning me anything.
 
 
From: Sharon Lucas [mailto:luc...@us.ibm.com] 
Sent: Friday, April 15, 2011 8:46 PM
To: Lohchab, Sanjeev
Subject: Re: [staf-users] How to pass prams to process request using 
submit2
 
You are not specifying the PROCESS START request properly. It is PARMS not 
PARAMS and since the parms contains a space, you must either enclose the 
parms value in double quotes or use the ColonLengthColon format which  you 
can do by using the STAF::WrapData function as talked about in section 
"7.2 Option Value Formats" in the STAF User's Guide at 
http://staf.sourceforge.net/current/STAFUG.htm#HDROVFORM.  Better yet, 
when you specify the SHELL option you can specify the command and 
parameters in the command value.  Also, since you're submitting the 
request synchronously by specifying the kReqSync option using the submit2 
method, you might as well use the submit API instead as it is equivalent. 
Here's an example (note this example is very similar to an example in the 
STAF Perl User's Guide at http://staf.sourceforge.net/current/STAFPerl.htm
. 

# Register with STAF and get a STAF handle

$handle = STAF::STAFHandle->new("MyProcessTest"); 

if ($handle->{rc} != $STAF::kOk) { 
   print "Error registering with STAF, RC: $handle->{rc}\n"; 
   exit $handle->{rc};
} 

# Submit a PROCESS START request and wait for it to complete

my $machine = "local";
my $command = "/bin/rpm -q AvmarClient";
my $request = "START SHELL COMMAND ".STAF::WrapData($command).
             " RETURNSTDOUT RETURNSTDERR WAIT";

print "\nSTAF $machine PROCESS $request\n";

my $result = $handle->submit($machine, "PROCESS", $request);

if ($result->{rc} != $STAF::kOk) {
   print "Error on STAF $machine PROCESS $request\n";
   print "Expected RC: 0\n";
   print "Received RC: $result->{rc}, Result: $result->{result}\n";
   exit $result->{rc}; 
}

--------------------------------------------------------------
Sharon Lucas
IBM Austin,   luc...@us.ibm.com
(512) 286-7313 or Tieline 363-7313




From:        <sanjeev.lohc...@emc.com> 
To:        <staf-users@lists.sourceforge.net> 
Date:        04/15/2011 05:46 AM 
Subject:        [staf-users] How to pass prams to process request using 
submit2 




Hi,

I am automating the linux and AIX package installation process.

Using Perl API I am using the following command:

$cmdResult = $fHandle->submit2($STAF::STAFHandle::kReqSync,"$machineName", 
"process", "start command /bin/rpm params -q AvmarClient returnstdout 
returnstderr wait");

But it fails with error:

Invalid command: /bin/rpm -q AvamarClient-6.0.100-580
The command is not a file or does not have execute permissions.
OS RC 2

But same thing if I am executing:

staf local process start command /bin/rpm parms "-q AvamarClient" 
returnstdout retrunstderr wait

it works fine.  I would like to know how could we pass the parms option 
using submit2 call.

Regards
Sanjeev

------------------------------------------------------------------------------
Benefiting from Server Virtualization: Beyond Initial Workload 
Consolidation -- Increasing the use of server virtualization is a top
priority.Virtualization can reduce costs, simplify management, and improve 

application availability and disaster protection. Learn more about 
boosting 
the value of server virtualization. http://p.sf.net/sfu/vmware-sfdev2dev
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users
------------------------------------------------------------------------------
Benefiting from Server Virtualization: Beyond Initial Workload 
Consolidation -- Increasing the use of server virtualization is a top
priority.Virtualization can reduce costs, simplify management, and improve 
application availability and disaster protection. Learn more about boosting 
the value of server virtualization. http://p.sf.net/sfu/vmware-sfdev2dev
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users

Reply via email to