environmentRebol has a native get-env function to read environment variables. For example, to test if your JAVA_HOME (JDK installation directory), CLASSPATH (for Java imports), CATALINA_HOME (for Tomcat) environment variables have been set, type in Rebol Console :


get-env "JAVA_HOME"
get-env "CLASSPATH"
get-env "JRE_HOME"
get-env "CATALINA_HOME"

To parse your environment variable, just use parse/all (do not forget /all otherwise space will be also taken as delimiter):


parse/all get-env "CLASSPATH" ";"

which will output something like this:


>> parse/all get-env "CLASSPATH" ";"
== ["." {t:\tomcat\lib\servlet.jar}]

So if you want to check that you did have current path “.” in your classpath, you would check it like this (do not omit /all refinement once again):


if none? find (parse/all get-env "CLASSPATH" ";") "." [
    print "Don't forget to add current path to your CLASSPATH ! "
]

Same if you want to check that you have added javac, java, PHP or whatever in your PATH environment variable:


if none? find (parse/all get-env "PATH" ";") "jdk" [
    print "Don't forget to add Javac dir in your PATH ! "
]

if none? find (parse/all get-env "PATH" ";") "jre" [
    print "Don't forget to add Java dir in your PATH ! "
]

if none? find (parse/all get-env "PATH" ";") "PHP" [
    print "Don't forget to add PHP dir in your PATH ! "
]

To ease the syntax, you can put this function in your user.r file:


check-env-path: func[what /local result][
    if/else none? result: find (parse/all get-env "PATH" ";") what [
        print [ rejoin [{"} what {"}] "not found in your PATH Environment Variable ! "]
    ][print result]
]

and call it like this:


check-env-path "PHP"

which would output for example:


>> check-env-path "PHP"
"PHP" not found in your PATH Environment Variable !
>>

For a list of Windows Environment variables see Vista Environment Variables and XP Environment Variables (TEMP or TMP variable, …). For example, APPDATA may contain your Rebol user.r file depending on the version of Rebol and OS.

To get the path of Windows/System32 use this trick (does function is synonym of func without the need to pass arguments):


system32-dir: does [
    path: get-env "COMSPEC"
    until [(rest: back remove back tail path) =  "\"]
    head rest
]

So if want to call the Environment Variables Control Panel from Rebol Console, you could create this function:


env-panel: does[
    call rejoin [ {"}  system32-dir "SystemPropertiesAdvanced.exe"  {"}]
]

And to call ODBC32 from Rebol Console, you could create this function:


ODBC32: does [
    call rejoin [ {"}  system32-dir "odbcad32.exe"  {"}]
]

Bookmark and Share

Recent Articles