[Tutor] Re[2]: [Tutor] Re[2]: [Tutor] ksh and SAS questions

adeline_j_wilcox@ccMail.Census.GOV adeline_j_wilcox@ccMail.Census.GOV
Mon, 07 Jun 1999 12:29:42 -0400


     
     While you all were quickly responding to my last inquiry I was 
     renewing my acquaintance with the business that parents cannot 
     inherit from child processes. The script setcm.ksh exports CATI.
     
     Guido's suggestion to run setcm.ksh manually as a dot script is 
     dangerously impractical in our environment. I don't own setcm.ksh 
     and don't care to seek to change it.
     
     The latest version of my script follows. It hangs after running 
     setcm.ksh. No doubt the fix is simple but here at the Bureau of 
     the Census we are too busy now for leisurely study of manuals.
     
     Adeline
     
#!/usr/local/bin/python
#PROGRAM: recheck.py
#FUNCTION: execute Barbara's RECHECK program
#INPUTS: rofr.txt
#OUTPUTS: rofr.sas, ccMail message
#CALLS TO: Python os, sys, and string modules, recheck.sas
#SPECIAL NOTES: Have not yet figured out how to automate input of the rofr file
#AUTHOR: Adeline Wilcox         DATE: 05Apr99
#Written with the assistance of Andrew Kuchling and especially Tim Peters
#UPDATED:                       DATE: 
import os, sys 
os.system('/op/ctl/prod/scripts/setcm.ksh')
os.system('sed \'1,4d\' setcm.out > setcm.txt')
os.system('awk \'{print $2}\' > rccatimo.txt')
import string
output = os.popen('rccatimo.txt; print $CATI').read()
month = string.strip(OUTPUT)

sys.stdin = open('/op/ctl/prod/data/ro' + month +'.txt','r')
lines = sys.stdin.readlines()
for i in range(len(lines)):
    line = lines[i]
    lines[i] = "'" + string.rstrip(line) + "'"
sys.stdout= open('/op/ctl/test/data/rofr.sas','w')
print "if rofr in (" + string.join(lines, ", ") + ") then output;"

file = open("/op/ctl/test/reports/mg" + month + ".txt", 'w')
file.write("Output is /op/ctl/test/data/rc" + month + ".txt and ready for your 
review\n")
file.close()

#if I dont close the file, SAS does not get quotes around last value of rofr
sys.stdout.close()
#os.system("$SASDIR/sas /op/ctl/prod/prgms/recheck.sas -sysparm " + month + \ " 
-log /op/ctl/prod/logs/recheck.log." + month ")
os.system("mailx -s 'Recheck " + month + " run for you \' 
Adeline.J.Wilcox@ccmail.census.gov < /op/ctl/test/reports/mg" + month + ".txt")

     


______________________________ Reply Separator _________________________________
Subject: Re: [Tutor] Re[2]: [Tutor] ksh and SAS questions 
Author:  David Ascher <da@ski.org> at SMTP-GATEWAY
Date:    6/4/1999 1:46 PM


On Fri, 4 Jun 1999 adeline_j_wilcox@ccMail.Census.GOV wrote:

>      Well, I can't see the error in the following script. Running 
>      SunOS 5.5.1. When I run my Python script, I get this error 
>      message:
>      
> Traceback (innermost last):
>   File "recheck.py", line 14, in ?
>     month = os.environ['CATI']
>   File "/usr/local/lib/python1.5/UserDict.py", line 12, in __getitem__
>     def __getitem__(self, key): return self.data[key]
> KeyError: CATI

This means that there is no environment variable called CATI when you run
line 14 -- if that was supposed to be set by

>     12  os.system('/op/ctl/prod/scripts/setcm.ksh')

then there's something wrong with that script.  I don't know the Korn
shell, but it could be that you need to specify something in that shell to
make the environment variables "stick" after execution.  In bash, I
believe it's the "export" command.

--david