Thanks for the clarification Mark.
I have modified the programming so that is now provides a message to the user when a bad value is asked for.
This is a big improvement over forcing Sesame to shut down.
Function fnGetEnvVariable(vEnvVariable as String) as String
/* ==========================
Created by Bob Hansen, Sensible Solutions Inc., Salem NH rmhansense@sensiblesolutions.org
NOTE: This will not work in WIN9X environments.
It will work in XP/2K environments with the following qualification.
Sending SET plus a variable name will return ALL names that begin with the name asked for.
Example SET Temp may return many names that start with Temp.
Check your own operating system for more infor re the SET command.
In Microsoft systems type SET /? into the command prompt window or on the Start,Run utility
vAction has different values remarked out for Linux systems, provided by Mark Lasersohn.
// ======================================
*/
var vEnvFile as String //Temp file name to hold system variable info
var vOK as Int //For @SHELL
var vFileHandle1 as Int //Identifier for temp file to be opened
var vEnvValueString as String //File string containing system variable info
var vEnvValue as String //Value for the specified system variable
var vPos as Int //Position indicator in string
var vLen as Int //Length of a string
var vBatchFile as String //Name of temp batch file
var vAction as String //The String to retrieve the environment value
vEnvFile = "GetEnvValue.txt"
vEnvValueString = ""
vBatchFile = "GetEnvValue.bat"
vAction = "SET " + vEnvVariable +" >" + vEnvFile
//For LINUX, use one of the following lines for vAction instead of the line above.
//depending on which shell (sh, ksh, csh, bash, tcsh, ...), is running.
//vAction = "set | grep -i " + vEnvVariable + " > " + vEnvFile
//vAction = "printenv | grep -i " + vEnvVariable + " > " + vEnvFile
//If file exists for someone else then wait 5 seconds and try again.
While FileExists(vEnvFile) {
LOITER(5000)
FileDelete(vEnvFile)
}
//Start Function Execution =======================================
//Delete file if it exists
If FileExists(vBatchFile) THEN {
FileDelete(vBatchFile)
}
//Create Temp Batch File =======================
vFileHandle1 = fileOpen(vBatchFile)
//Write to Temp Batch File =======================
FileWriteLn(vFileHandle1,"@echo off")
FileWriteLn(vFileHandle1, vAction)
FileWriteLn(vFileHandle1, "IF errorlevel==1 goto NG")
FileWriteLn(vFileHandle1, "")
FileWriteLn(vFileHandle1, "::OK")
FileWriteLn(vFileHandle1, "goto End")
FileWriteLn(vFileHandle1, "")
FileWriteLn(vFileHandle1, ":NG")
FileWriteLn(vFileHandle1, "echo BAD-BAD-BAD > " + vEnvFile)
FileWriteLn(vFileHandle1, "")
FileWriteLn(vFileHandle1, ":End")
//Close Batch file
FileClose(vFileHandle1)
//Run temp batch file to redirect value to a temp file
vOK=@AsynchShell(vBatchFile)
//Delete File =======================
Loiter(500)
If FileExists(vBatchFile) THEN {
FileDelete(vBatchFile)
}
//Read the file line and delete the file
vFileHandle1 = FileOpen(vEnvFile)
FileSeek(vFileHandle1,0)
FileReadLn(vFileHandle1, vEnvValueString)
FileClose(vFileHandle1)
FileDelete(vEnvFile)
//Parse out the variable, from position of "=" to end of string
vLen = @Len(vEnvValueString)
vPos = @InStr(vEnvValueString,"=")
If vPos = 0 THEN {
vEnvValue = "Environment variable " + vEnvVariable + " is not defined"
} ELSE {
vEnvValue = @MID(vEnvValueString, vPos+1, vLen-vPos)
}
Return vEnvValue
End Function
//=============================================================
I have been unable to stop the "black box flash", but that is a minor inconvenience right now.
I have also placed this programming into the forum section for Programming Examples, under the subject:
Get Environment Variable Value as a general purpose function. Additional notes and history are included at that location.