Be sure that you set the PYTHONPATH environment variable in the 
environment in which STAFProc is running (as opposed to the command line 
environment in which you are submitting the STAF PROCESS START request). 
This is because when running a command via STAF, the command is run in the 
environment in which STAFProc is running, not in the environment of the 
command line where you submitted the STAF PROCESS START request. 

When debugging a problem using the STAF PROCESS START request to run a 
command, I recommend that you redirect stdout/stderr for the command you 
are running and specify the WAIT option to wait for the command to 
complete so that you can immediately see the return code and stdout/stderr 
result from running the command.  For example, RC 2 (which is the return 
code you were getting when running oldSTAFPython) is the Linux operating 
system return code that means FileNotFound.  You said you were running:

STAF local PROCESS START COMMAND python PARMS "oldSTAFTestcase"

This is incorrect as you need to specify the .py extension.  Without the 
.py extension, it will fail with RC 2 when running this python command 
without using STAF as follows:

[root  tmp]# python oldSTAFTestcase
python: can't open file 'oldSTAFTestcase': [Errno 2] No such file or 
directory
[root tmp]#

Also, when running this command via STAF, you need to specify the path to 
oldSTAFTestcase.py so that the system can find this file (e.g. 
/tmp/oldSTAFTestcase.py).  This is because when running a command via 
STAF, the command is run in the environment in which STAFProc is running, 
not in the environment of the command line where you submitted the STAF 
PROCESS START request.  So, for example, the following request (which is 
like yours)  fails with RC 2 (Linux operating system return code 2 means 
FileNotFound) as follows because python cannot find file oldSTAFTestcase:

# STAF local PROCESS START COMMAND python PARMS oldSTAFTestcase 
RETURNSTDOUT STDERRTOSTDOUT WAIT
Response
--------
{
  Return Code: 2
  Key        : <None>
  Files      : [
    {
      Return Code: 0
      Data       : python: can't open file 'oldSTAFTestcase': [Errno 2] No 
such
file or directory

    }
  ]
}
#

However, if I correctly specify the full name of the file (e.g. 
/tmp/oldSTAFTestcase.py), then the STAF PROCESS START request works fine. 
Note I changed the count from 100 to 5 on oldSTAFTestcase.py so that it 
would complete quickly when debugging this issue.

# STAF local PROCESS START COMMAND python PARMS /tmp/oldSTAFTestcase.py 
RETURNSTDOUT STDERRTOSTDOUT WAIT
Response
--------
{
  Return Code: 0
  Key        : <None>
  Files      : [
    {
      Return Code: 0
      Data       : OS Name: Linux
Loop # 0
Loop # 1
Loop # 2
Loop # 3
Loop # 4

    }
  ]
}
#

Or, instead of fully-qualifying the path to the command, you could specify 
the WORKDIR option with the directory where the oldSTAFTestcase.py file 
resides.  For example:

# STAF local PROCESS START COMMAND python PARMS "oldSTAFTestcase.py" 
WORKDIR /tmp RETURNSTDOUT STDERRTOSTDOUT WAIT
Response
--------
{
  Return Code: 0
  Key        : <None>
  Files      : [
    {
      Return Code: 0
      Data       : OS Name: Linux
Loop # 0
Loop # 1
Loop # 2
Loop # 3
Loop # 4

    }
  ]
}
#

Note that I personally prefer using  the COMMAND option to specify the 
complete command instead of using the PARMS option.  When you do this, you 
must also specify the SHELL option.  For example:

# STAF local PROCESS START SHELL COMMAND "python /tmp/oldSTAFTestcase.py" 
RETURNSTDOUT STDERRTOSTDOUT WAIT
Response
--------
{
  Return Code: 0
  Key        : <None>
  Files      : [
    {
      Return Code: 0
      Data       : OS Name: Linux
Loop # 0
Loop # 1
Loop # 2
Loop # 3
Loop # 4

    }
  ]
}
#

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




From:   Ashokkumar Naidu <ashokkuma...@globaledgesoft.com>
To:     staf-users@lists.sourceforge.net, 
Date:   07/05/2013 07:19 AM
Subject:        Re: [staf-users] Problem when I am running Python Script 
in STAF Environment



Hai,

My STAF Environment Details:

                python version is 2.7.3
                java version 1.6
                os is ubuntu 12.04

                $ STAF local MISC LIST PROPERTIES  output is,

                    version     : 3.4.12
                    platform    : linux
                    architecture: 32-bit
                    installer   : IA
                    file        : STAF3412-setup-linux.bin
                    osname      : Linux
                    osversion   : *
                    osarch      : x86

1. Python Command
staf local process start command python parms "oldSTAFTestcase"

Response
--------
5

2. Java Command
staf local process start command java parms "STAFTestcase"

Response
--------
8

Response for Commands
staf local process list handles

Response
--------
Handle Command Start Date-Time   End Date-Time     Return Code
------ ------- ----------------- ----------------- -----------
5      python  20130705-12:54:51 20130705-12:54:52  2    
8      java    20130705-12:58:29 20130705-12:58:40      0  

        Here, I am attaching files which producing above return codes. so 
kindly help me.

        When I am running the oldSTAFTestcase.py with python seperately, 
it's working fine

Command:   $ python oldSTAFTestcase.py 

OS Name: Linux
Loop # 0
Loop # 1
Loop # 2
....
....
....
Loop # 97
Loop # 98
Loop # 99

But when i am running under staf environment it's giving response code 2.
I exported PYTHONPATH

export PYTHONPATH=/usr/local/staf/lib:${PYTHONPATH}
(oldSTAFTestcase.py exist in /usr/local/staf/lib)



Thanks & Regards,
N. Asok Kumar[attachment "oldSTAFTestcase.py" deleted by Sharon 
Lucas/Austin/IBM] [attachment "STAFTestcase.java" deleted by Sharon 
Lucas/Austin/IBM] 
------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users

------------------------------------------------------------------------------
See everything from the browser to the database with AppDynamics
Get end-to-end visibility with application monitoring from AppDynamics
Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users

Reply via email to