carl@CITHEX.CALTECH.EDU (12/10/87)
> Can you answer my question about finding the LOG file (not the COM > file returned by F$ENVIRONMENT) of the BATCH assuming it was sent > with: > $ submit/log=sys$disk:[] > but not from the same directory as that of the COM file. > I am trying to find the directory the user was in when he did the > SUBMIT command and set def to it. The following procedure is a bit more general than what you asked for in that it places the full file spec of the log file in the DCL variable FILENAME, regardless of what qualifiers (with the exeception of /NOLOG) were used with the submit command. It will fail if the batch job sets its process name or opens a second file with the same filename and filetype in the same directory on the same disk before the code is invoked, or if it is executed from a subprocess. If it fails, it may terminate the job; I haven't tried to make it bulletproof. I therefore suggest placing it (or a reference to it) at the top of the procedure you're submitting. $!****************************************************************************!$ $! GET_LOG_FILE_NAME.COM - get a full file specification of the current $! job's log file. This procedure should be executed from the top-level $! process before changing the process name. You should not have any files $! open at this point other than the process-permanent files. $! Copyright (C) 1987, Caltech Odd Hack Committee, no rights reserved $! $! Generate temp file name $ PID = F$GETJPI("","PID") $ FILE = "SYS$SCRATCH:" + PID + ".TMP" $! Use the output of SHOW QUEUE/BATCH/FULL to get the log file spec, less $! version number $ MY_NUM = F$GETJPI("","PRCNAM") - "BATCH_" $ SHOW QUEUE/BAT/ALL/FU/OUT='FILE' $! Select only info for the current job $ SEARCH/OUTPUT='FILE' 'FILE';-1 " ''MY_NUM' "/WINDOW=(0,2) $ DELETE 'FILE';-1 $ OPEN/READ FILE 'FILE' $ READ FILE LOGSPEC $ READ FILE LOGSPEC $ READ FILE COMSPEC $ CLOSE FILE $ DELETE 'FILE'; $ COMSPEC = F$ELEMENT(0," ",F$EDIT(COMSPEC,"TRIM,COMPRESS")) $ LOGSPEC = F$ELEM(0," ",F$EXT(F$LOC(" /LOG=",LOGSPEC)+6,255,LOGSPEC)) $! We've now got filespecs for both the procedure and the log file $! Clean up rooted directory syntax $ LOGSPEC = LOGSPEC - "][" - "][" - "][" - "][" - "][" - "][" - "][" $! Get a default filename for the log file $ COMSPEC = F$PARSE(COMSPEC,,,"NAME","SYNTAX_ONLY") $ LOGSPEC = F$PARSE(LOGSPEC,COMSPEC,,,"SYNTAX_ONLY") $! Remove the device name and version fields from the log file spec $ LOGSPEC = "[" + F$ELEMENT(1,"[",F$ELEMENT(0,";",LOGSPEC)) $! Use SHOW DEVICE/FILES to get a list of specifications of open files, $! complete with version numbers $ SHOW DEVICE/FILES/NOSYSTEM/OUTPUT='FILE' SYS$OUTPUT: $! Throw away all but our logfile $ SEARCH/OUTPUT='FILE' 'FILE';-1/MATCH=AND " ''PID' ",'LOGSPEC' $ OPEN/READ FILE 'FILE' $ READ FILE REC $! Make sure we don't have a second file with the same name open $ READ/ERR=NEXT FILE REC $ WRITE SYS$OUTPUT "WARNING: LOGFILE SPEC NOT UNIQUE WITHIN THIS PROCESS" $ NEXT: CLOSE FILE $ DELETE 'FILE';,; $! Remove extraneous info and insert device name again $ FILENAME == F$TRN("SYS$OUTPUT")+F$ELEM(2," ",F$EDI(REC,"TRIM,COMPRESS")) $!****************************************************************************!$