Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo
Using process in STAX script I am running Python script(using PySTAFv3 in python script), Now I want to print message of python script to STAXMon window.
I have created a Handle
Have called the process to start python script (can pass handle number to python script)
while running process I want to print the message from python script to STAXMon ..How to do this ?
any other help on this is appreciated.
The Python script can submit a "SEND MESSAGE" request to the STAX service. See section "SEND MESSAGE" in the "Request Syntax" section in the STAX User's Guide at http://staf.sourceforge.net/current/STAX/staxug.html#Header_Send. The Python script will need to know the STAX Job ID which you could pass as a parameter to the Python script via the <process> element by passing variable STAXJobID which is provided by STAX (as talked about in section "STAX Variables" in the STAX User's Guide at http://staf.sourceforge.net/current/STAX/staxug.html#Header_StaxVariables).
I am passing STADHandle to Python and using queue I am sending message to that particular Handle.
In STAX Job I am launching the process which is calling python file and start executing, Now python is also sending message to STAX handle but now I want to get message from the queue at the time it added to the queue and want to print till it get end Notification. How to read message from queue and print it on run time ?
<!- SNIP from STAX file
handlename = "atry"
<message>"Welcome To ABC"</message>
<message>"This script establish the connection"</message>
<call function = "'staf-newhandle'">
Handle_number = STAXResult
<message>"Handle_number is %s" %Handle_number</message>
<message>"Handle %s Created Successfully" %handlename</message>
<message>"Starting Python Process"</message>
<call function = "'stafprocess'">
'command': "python c:\\STAF\\trial\try.py %s %s" %(STAXJobID,Handle_number)
<message>"Waiting for End Notification"</message>
<call function = "'staf-queue-listmsg'">
'handle': "%s" %Handle_number
<message>"Deleting handle %s Handle_number %s " %(handlename,handlename)</message>
<call function = "'staf-deletehandle'">
<message>"handle %s Handle_number %s deleted " %(handlename,Handle_number)</message>
Python File code:
from PySTAFv3 import *
JobID_fromSTAX = sys.argv;
Handle_fromSTAX = sys.argv;
handle = STAFHandle("MyPythonTest")
message = 'Python script with handle %d added to queue' % (handle.handle)
request = 'QUEUE MESSAGE %s handle %s ' % (wrapData(message), wrapData(Handle_fromSTAX))
result = handle.submit("local", "QUEUE", request)
So you didn't really want to send a message to the STAX Monitor's "Messages" section as I had originally thought you did from your original description.
You want to send a message from your Python script (executed via a <process> element in your STAX job) to a handle you created in your STAX job and receive the message. If you explained more what you're trying to do and why you think you want to do it this way, I might be able to suggest a better way. For example, if you simply want to know when the Python script ends, then you'll know that when the <process> element ends and you don't need to send messages between the Python script and the STAX job.
But, if you really have a need for sending a message from the Python script to the STAX job, then look at the "Sample STAX Job 3 - Creating a STAF Handle and Using it's Queue" example in the STAX User's Guide at http://staf.sourceforge.net/current/STAX/staxug.html#Header_SampleJob3. It shows how you can use a STAF Handle that you create in your STAX job and use it to submit a QUEUE GET request. Note that to be able to get a message off the STAF Handle's queue while the process is running you'll need to be running these two actions in parallel (e.g. using the <parallel> element).
In short, I want to do the following:
1. will Launch a python script using process from STAX script
2. Python script will run the certain test.
3. I want to print step by step message of my test execution to STAX Monitor.
4. Once my test will end, It will send PASS or FAIL message to STAX script
5. After receiving Test notification, STAX will show the result.
Ok, then you don't need to use the QUEUE service or create a new STAF Handle in your STAX job. All you have to do is pass the STAX Job ID to the Python script in your <process> element and have your Python script submit a 'SEND JOB %s MESSAGE %s' request to the STAX service on the machine where the STAX service is running specifying the STAX Job ID for the value of the JOB option to send a message to the STAX Monitor's "Message" section. For example:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE stax SYSTEM "stax.dtd">
<message log="1">'Send a message from Python script to STAX Monitor'</message>
<command mode="'shell'">'python C:/test/sendMsg.py %s' % (STAXJobID)</command>
'Python Script RC=%s, STAFResult=%s, STAXResult=\n%s' % (RC, STAFResult, STAXResult)
And here's the content of C:\test\sendMsy.py:
from PySTAFv3 import *
# Get STAX Job ID passed as an argument
staxJobID = sys.argv
# Set to the hostname or /IP address of your STAX service machine
# (or 'local' if the Python script is run on your STAX service machine)
staxMachine = 'local'
# Create a STAF handle works to use to submit STAF service requests
handle = STAFHandle('MyPythonTest')
except STAFException as e:
print('Error registering with STAF, RC: %d Result: %s' % (e.rc, e.result))
# Send a status message to the STAX Monitor
message = 'Python script is in Step 1'
request = 'SEND JOB %s MESSAGE %s' % (staxJobID, wrapData(message))
result = handle.submit(staxMachine, 'STAX', request)
if (result.rc != STAFResult.Ok):
print('Error: RC=%s Result=%s\nSTAF %s STAX %s' % \
(result.rc, result.result, staxMachine, request))
print('\n*** Test successful ***')
# Un-register the STAF handle
result = handle.unregister()
if (result != STAFResult.Ok):
print('Error unregistering with STAF, RC: %d' % result)
# Test passed - Return 0
Then when I run this STAX job via the STAX Monitor, I see the following in the "Messages" tab of the STAX Monitor:
20120619-13:59:59 Send a message from Python script to STAX Monitor
20120619-13:59:59 Python script is in Step 1
20120619-13:59:59 Python Script RC=0, STAFResult=None, STAXResult=
Thanks It's working fine .. will ping you again if get stuck .. I am developing automation framework while STAF is base :-)