Hi,

First, you need to understand that STAX uses Jython 2.1, which is
equivalent to Python 2.1.  The Python documentation for subprocess
(http://docs.python.org/library/subprocess.html#subprocess-replacements)
indicates that it was added in Python 2.4, so it is not available with
Jython 2.1.  Furthermore, in the STAX User's Guide section "Appendix F:
Jython and CPython
Differences" 
(http://staf.sourceforge.net/current/STAX/staxug.html#Header_CPythonDiffs)
 it is documented that "Some standard CPython modules depend on operating
system calls that are not available under Java. The most notable of these
is os, which actually does run in Jython, but is missing much of its
functionality."

There are other ways you could do this.  For example, you could just run
the "ps -ea...." via a <process> element.  For example:

      <process>
        <location>'local'</location>
        <command mode="'shell'">'ps -eaf | grep %s' %
(processname)</command>
        <stderr mode="'stdout'"/>
        <returnstdout/>
      </process>

      <message log="1">STAXResult[0][1]</message>

Or, if you really wanted to run your Python code, you could have it in
a .py file on the system (and have Python 2.4 or later installed on the
system), and execute it via a process element:

      <process>
        <location>'local'</location>
        <command mode="'shell'">'/opt/Python-2.4/bin/
python /tests/myscript.py'</command>
        <stderr mode="'stdout'"/>
        <returnstdout/>
      </process>

Thanks,
David


                                                                       
 David Bender          11501 Burnet Rd.   Phone (T/L): 1-512-286-5315  
 STAF/STAX Development Bldg. 903-5B002    (363-5315)                   
                       Austin, TX         ITN: 23635315                
 IBM Software Group,   78758-3400         Email: bda...@us.ibm.com     
 WPLC                                                                  
                                                                       
                                                                       






                                                                       
  From:       "Raja Narayanan" <v_rajnara...@rediffmail.com>           
                                                                       
  To:         "staf-users " <staf-users@lists.sourceforge.net>         
                                                                       
  Date:       03/18/2011 08:45 AM                                      
                                                                       
  Subject:    [staf-users] HOW to run python code in STAX XML Program  
                                                                       





Hello Staf-users,

Im trying to run the following python code in STAX XML program within
<script>. But facing RC:4001 error submitting executing request problem.

<script>
         import os
         import signal
         import subprocess

       # Change this to your process name
          processname = "server"

          def findThisProcess(process_name):
          ps = subprocess.Popen("ps -eaf | grep "+process_name, shell=True,
stdout=subprocess.PIPE)
          output = 'ps.stdout.read()'
          ps.stdout.close()
          ps.wait()
          return output
 </script>

Q1: Does the method I have followed is correct or not?
Q2: Do we need to set up python installer path or env variable need to set
before running the python code.

Please help

Thanks,
V Raja


------------------------------------------------------------------------------

Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users

<<inline: graycol.gif>>

<<inline: ecblank.gif>>

------------------------------------------------------------------------------
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users

Reply via email to