And you can obtain values for the arguments (e.g. logName, remoeAddr,
remoteName, localFiles) from a config file instead of hard-coding them.
If the config file resides on the STAX service machine (the "local"
machine), you can use Python APIs to read the file. For example, you
could replace the <script> element that hardcodes logName, remoteAddr,
remoteName, and localFiles with something like the following depending on
the format of your config file that contained these values:
<script>
import re
# Set to wherever your config file is located
myConfigFile = 'C:\\testa\\test.cfg'
# Read the config file and assign each line in the file to a lines
list
file = open(myConfigFile, 'r')
lines = file.readlines()
file.close()
# Process depending on the format of your config file.
# For example, if it contained lines like:
# logName = C:\testa\abc_abc.txt
# remoteAddr = 0A5CAB0999C123D
# remoteName = ABCD123
# localFiles = C:\test2\T_Log.txt
for line in lines:
if line.find('=') != -1:
[key, value] = line.split('=', 2)
key = key.strip()
if key == 'logName':
logName = value.strip()
elif key == 'remoteAddr':
remoteAddr = value.strip()
elif key == 'remoteName':
remoteName = value.strip()
elif key == 'localFiles':
localFiles = value.strip()
</script>
--------------------------------------------------------------
Sharon Lucas
IBM Austin, luc...@us.ibm.com
(512) 286-7313 or Tieline 363-7313
----- Forwarded by Sharon Lucas/Austin/IBM on 08/04/2011 02:17 PM -----
From: Sharon Lucas/Austin/IBM
To: Prasant Biswal <prasantkubis...@gmail.com>
Date: 08/04/2011 02:14 PM
Subject: Re: [staf-users] How to call function with different
arguments
I made some modifications to your STAX xml so that it will run the
following command:
C:\test\Run.exe -AutoRun -Log=C:\testa\abc_abc.txt -Overwrite=false
-Command=SendFiles -RemoteAddr=0A5CAB09999C123D -RemoteName=ABCD123
-Timeout=0sec -LocalFiles=C:\test2\T_Log.txt -CustomTest=false
-PassExit=false -FileOnPass=false -FailExit=false -FileOnFail=false
-AutoRunOnExit
Of course since I don't have your C:\test\Run.exe I could run the
<process>. Here's the STAX job I successfully ran (except with the
<process> commented out).
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE stax SYSTEM "stax.dtd">
<stax>
<defaultcall function="main"/>
<script>
# Python requires a \ to be escaped with a \ (e.g. \\) or you can use
a /
logName = 'C:\\testa\\abc_abc.txt'
remoteAddr = '0A5CAB09999C123D'
remoteName = 'ABCD123'
localFiles = 'C:\\test2\\T_Log.txt'
</script>
<function name="main">
<sequence>
<!-- <import machine="ImportMachine" file="ImportFile1"/> -->
<call function="'UIAutomation'">[logName, remoteAddr, remoteName,
localFiles]</call>
</sequence>
</function>
<function name="UIAutomation">
<function-list-args>
<function-required-arg name="logName"/>
<function-required-arg name="remoteAddr"/>
<function-required-arg name="remoteName"/>
<function-required-arg name="localFiles"/>
</function-list-args>
<sequence>
<script>
# I split up the assignment of the command and its parameters into
multiple lines
# for easier readability
parms = '-AutoRun -Log=%s -Overwrite=false -Command=SendFiles
-RemoteAddr=%s ' % (logName, remoteAddr)
parms = '%s -RemoteName=%s -Timeout=0sec -LocalFiles=%s' % (parms,
remoteName, localFiles)
parms = '%s -CustomTest=false -PassExit=false -FileOnPass=false' %
(parms)
parms = '%s -FailExit=false -FileOnFail=false -AutoRunOnExit' %
(parms)
# Need to use forward slashes instead of backward slashes (or else
escape by specifying \\)
command = 'C:/test/Run.exe %s' % (parms)
</script>
<!-- Logging your command is helpful when you are debugging -->
<log message="1">command</log>
<process>
<location>'local'</location>
<command mode="'shell'">command</command>
<stderr mode="'stdout'"/>
<returnstdout/>
</process>
<log message="1">'Process RC: %s, STAFResult: %s, STAXResult: %s' %
(RC, STAFResult, STAXResult)</log>
</sequence>
</function>
</stax>
--------------------------------------------------------------
Sharon Lucas
IBM Austin, luc...@us.ibm.com
(512) 286-7313 or Tieline 363-7313
From: Prasant Biswal <prasantkubis...@gmail.com>
To: Sharon Lucas/Austin/IBM@IBMUS
Date: 08/04/2011 01:15 PM
Subject: Re: [staf-users] How to call function with different
arguments
Hi Sharon,
Thanks for the help, i tried to pass the 4 arguments (argA,
argB,argC,argD) with values and got lots of error , can ypu please look
at the script once:
it is showing error while parsing "argC" and <command> execution .
Script :
<function-list-args>
<function-required-arg name="argA"/>
<function-required-arg name="argB"/>
<function-required-arg name="argC"/>
<function-required-arg name="argD"/>
</function-list-args>
<sequence>
<process>
<location>'local'</location>
<command mode="'shell'">'C:\test\Run.exe -AutoRun -Log=%s -Overwrite=false
-Command=SendFiles -RemoteAddr=%s -
RemoteName=%s -Timeout=0sec -LocalFiles=%s -CustomTest=false
-PassExit=false -FileOnPass=false -FailExit=false -
FileOnFail=false -AutoRunExit'' % (argA, argB,argC,argD)</command>
</process>
<log message="1">'Process RC: %s, STAFResult: %s, STAXResult: %s' % (RC,
STAFResult, STAXResult)</log>
</sequence>
</function>
<defaultcall function="main"/>
<script>
argA = 'C:\testa\abc_abc.txt'
argB = '0A5CAB09999C123D'
argC = 'ABCD123'
argD = 'C:\test2\T_Log.txt'
</script>
<script>
ImportMachine = 'local'
ImportDirectory = 'C:\STAF\services\stax\samples\Test'
ImportFile1 = '%s/CopyofTest.xml' % (ImportDirectory)
</script>
<function name="main">
<sequence>
<!--<import machine="ImportMachine" file="ImportFile1"/>
-->
<call function="'UIAutomation'">[argA, argB,argC,argD]</call>
</sequence>
</function>
Is it possible to replace the arg with variables which will be read from a
config file?
Thanks ,
-Prasant
On Thu, Aug 4, 2011 at 9:36 PM, Sharon Lucas <luc...@us.ibm.com> wrote:
Yes you can pass arguments to STAX functions. It wasn't clear to me if
you were asking how to do this when calling a function within a STAX job
or if you were asking how to do pass arguments to a STAX job's starting
function when submitting it for execution via a STAX EXECUTE request.
You can pass arguments to a STAX job's starting function via the ARGS
option on a STAX EXECUTE request. Or, you can use the SCRIPT or
SCRIPTFILE option on a STAX EXECUTE request to use Python code to set
variables that can be accessed by your STAX job. For more information on
the options you can specify when submitting a STAX job via a STAX EXECUTE
request see the STAX User's Guide at
http://staf.sourceforge.net/current/STAX/staxug.html#Header_Execute.
Or, if you are reading from your.config file within the STAX job then you
could pass the variable values you obtain to any function when calling the
function.
See section "call: Call a Function" within the STAX User's Guide for more
information on calling a function with arguments (via a list, map, single
arg, etc) at
http://staf.sourceforge.net/current/STAX/staxug.html#Header_Call.
So, say you had a STAX function like the following that requires values to
be passed for argA and argB as a list.
<function name="startProcess">
<function-list-args>
<function-required-arg name="argA"/>
<function-required-arg name="argB"/>
<function-optional-arg name="argD" value="'xyz'"/>
</function-list-args>
<sequence>
<process>
<location>'local'</location>
<command mode="'shell'">'Run.exe -A=%s -B=%s -C -D=%s -E' % (argA,
argB, argD')</command>
</process>
<log message="1">'Process RC: %s, STAFResult: %s, STAXResult: %s' %
(RC, STAFResult, STAXResult)</log>
</sequence>
</function>
Within the STAX job you could call it as follows:
<script>
argA = 'abc'
argB = 'bcd'
</script>
<call function="'startProcess'">[argA, argB]</call>
Or, if this was the starting function for the STAX job you could pass
values for argA and argB when submitting the STAX job. For example:
STAF staxMachine STAX EXECUTE FILE /stax/job1.xml FUNCTION "startProcess"
ARGS "['abc', 'bcd']"
--------------------------------------------------------------
Sharon Lucas
IBM Austin, luc...@us.ibm.com
(512) 286-7313 or Tieline 363-7313
From: Prasant Biswal <prasantkubis...@gmail.com>
To: staf-users@lists.sourceforge.net
Date: 08/04/2011 09:18 AM
Subject: [staf-users] How to call function with different arguments
Dear Stafusers
Can you please help with below problems:
1.Can it possible to run an exe with multiple variable (some variables
will not change and some i need to read from a config file )
For example :Suppose i need to run the Run.exe using a multiple arguments:
Run.exe -A=abc -B=bcd -C -D=xyz -E
In this -C , -E will be kept constant (no changes) and -A and -B will be
read from config file and pass during calling the function.
Please let me know if it is possible using STAX.
Thanks,
Prasant
------------------------------------------------------------------------------
BlackBerry® DevCon Americas, Oct. 18-20, San Francisco, CA
The must-attend event for mobile developers. Connect with experts.
Get tools for creating Super Apps. See the latest technologies.
Sessions, hands-on labs, demos & much more. Register early & save!
http://p.sf.net/sfu/rim-blackberry-1
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users
------------------------------------------------------------------------------
BlackBerry® DevCon Americas, Oct. 18-20, San Francisco, CA
The must-attend event for mobile developers. Connect with experts.
Get tools for creating Super Apps. See the latest technologies.
Sessions, hands-on labs, demos & much more. Register early & save!
http://p.sf.net/sfu/rim-blackberry-1
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users