Invoking a Unix Shell Script from a WebFOCUS Procedure
I am looking for an example of invoking a Unix Shell Script from WebFOCUS Fex Code. I used following. It works successfully but does not return 33. It returns 0. Is this expected ? If so, how to get the actual return code of 33 ?
I tried SYSTEM, !, UNIX and SPAWN. The SPAWN silently returned zero no matter what the shell command/script was provided as an argument. I used the SPAWN with DEFINE and COMPUTE as stated in the manual and tried to generated a fake report with a TABLE FILE. No luck. It returned zero.
The SYSTEM, !, UNIX successfully ran the script (I can see the side effects by writing to some file) but with always zero return code. I tried getting the return code by assignment, by &RETCODE and by using -TYPE. I tried by putting return and exit statements in the script. I tried the return type as D2, D4 and D8. No luck.This message has been edited. Last edited by: Govind Jujare,
WebFOCUS 5.3.3 MRE - Solaris - Sun Web Server - Weblogic
January 30, 2006, 11:22 AM
Robin Lovell
A couple of ways to achieve this, both a little long-winded: 1. Have your shell script write the return code to a file and have WebFocus -READ the result from the file. If you first test for the existence of the file, using STATE, and don't find it, you also know you have an error. 2. Have your shell script set and export an environment variable, then use the WebFocus FGETENV() subroutine to read that variable.
But RC3 came back as 'FOCUS' in the fex code. I guess this is to be expected. Because in Unix the values of shell variables are not copied back from child process to the parent process (unless you explicitely send them through a file or pipe or socket .. etc).
I didn't try writing to files because of efficiency concerns ... I guess I will have it give it another thought.
WebFOCUS 5.3.3 MRE - Solaris - Sun Web Server - Weblogic
January 30, 2006, 03:11 PM
Govind Jujare
Hi Robin,
I been struggling to recollect information about the 'STATE' that you talked about (to check existence of a file). I am not able to find it in manuals. Actually that can help me to certain extent.
Thx,
WebFOCUS 5.3.3 MRE - Solaris - Sun Web Server - Weblogic
January 30, 2006, 04:42 PM
Robin Lovell
Govind,
This shows both methods working, and also the usage of STATE:
-* ttest.fex: FILEDEF SRCFILE DISK out.txt (RECFM V LRECL 80 -DEFAULT &RC3='ABCDEFGH' -DEFAULT &RC4='ABCDEFGH' -RUN !. ./scr.ksh -RUN
-SET &RC3 = FGETENV(4,'VAR1',20,'A20'); -RUN STATE ./out.txt -RUN -IF &RETCODE EQ 0 GOTO HAVDAT ; -TYPE File out.txt not found in current directory. -GOTO ENDIT
and this is the shell script: #!/bin/ksh # scr.ksh VAR1="MODIFY"; export VAR1 echo $VAR1 > ./out.txt
January 30, 2006, 09:48 PM
Govind Jujare
Robin, I got follg output. Is RC3 supposed to show up as 'MODIFY' ? I used an absolute path for scr.ksh (because I am in MRE).
IORET= 0
RC3=
RC4=MODIFY
To double check, I introduced a FPUTENV for VAR1 at the top of the fex and saw RC3 getting the value unchanged. I wonder what I am doing wrong. Thx for the tip on 'STATE'.
WebFOCUS 5.3.3 MRE - Solaris - Sun Web Server - Weblogic
January 30, 2006, 11:08 PM
Govind Jujare
Even though I was not able to make get the return code of the shell script OR get the env variable from shell script using 'FGETENV' .... the 'STATE' command worked proved sufficient in my case. OTOH, I see that all the output of the script is getting pumped into the generated HTML file in the form of comments. That helps me in figuring out what went wrong with the shell script. That ought to be enough in my case.
Thx,
WebFOCUS 5.3.3 MRE - Solaris - Sun Web Server - Weblogic
January 31, 2006, 08:12 AM
Robin Lovell
Make sure that you have the dot-space ". " before the shell script command. This should ensure that the environment variable is available to WebFocus.
!. scr.ksh
Robin
January 31, 2006, 01:33 PM
Govind Jujare
That is what I thought when I looked at the dot (current shell) in your script. Still the env var did not get updated to webfocus.
From the above, it seems that webfocus is spanning "sh". I do not see how it the value of env var from scr.ksh can propogate back to webfocus.
Thx,
WebFOCUS 5.3.3 MRE - Solaris - Sun Web Server - Weblogic
January 31, 2006, 02:25 PM
Robin Lovell
Hmmm. In that case I'm stumped.
January 31, 2006, 04:02 PM
Govind Jujare
If it has really worked for somebody, may be it is because of something in their environment. May be sh/ksh. May be MRE/self-serv. Anyway, thx for the "STATE" trick.
WebFOCUS 5.3.3 MRE - Solaris - Sun Web Server - Weblogic
January 31, 2006, 04:22 PM
Kevin Sherrard
This is may not help, but I will throw it out there.
FEX Code:
-*-SET &ECHO=ALL; -* -UNIX cd /opt/ibiqual/ibi/apps/baseapp -UNIX ./update.sh -*
SH Code:
#!/bin/ksh
java update > update.log
WebFOCUS 7.6.11 HF 6 Client Reporting Server/Caster 7.6.11 PDS Server on MVS DB2 1.46R Tandem 7.6.11 IWAY SQL Server 2000 Access
February 08, 2006, 02:56 PM
jbmuir
This is how we do it running WebFOCUS on Solaris:
-UNIX yourscript -IF &EXITRC NE 0 THEN GOTO WHATEVER;
of course, yourscript has to set the return code.
WF 7.1.6 moving to WF 7.7, Solaris 10, HTML,PDF,XL
February 08, 2006, 07:42 PM
Govind Jujare
No luck with 'UNIX' call. EXITRC showed zero even when the script did not exist. I ran -