Retrieve OS Environment  variable values

Dear All,
In all Operating System we can set the system environment variables in either Batch file(Windows) or script files (Unix Based operating system). Is there any way to retrive the variable values declared in the batch file or script file in throu java application without specifying -D param in java command
Thanks
ARvind

Personally, I use a little dirty trick to get the environment settings on Windows.
I have a batch file doing "set > output.txt". Then I call this batch file with Runtime.exec() and I parse the resulting output.txt file.
Not clean at all, but it works ;-)
David

Similar Messages

  • I am not getting User Environment Variable Value

    Hi Team,
    I have been Trying to recover variables values using an anonym procedure from Windows XP SP3
    I have already executed following procedure.
    BEGIN
    DECLARE
    gf_filelog UTL_FILE.file_type;
    v_file_log VARCHAR2 (1024) := ' ';
    gv_path_log VARCHAR2 (1024) := ' ';
    gv_path_log2 VARCHAR2 (1024) := ' ';
    gv_file_log VARCHAR2 (1024) := ' ';
    BEGIN
    DBMS_OUTPUT.put_line ( 'obteniendo valores of vars: '
    || gv_path_log
    || ' '
    || gv_file_log
    DBMS_SYSTEM.get_env ('ORACLE_HOME', gv_path_log);
    DBMS_SYSTEM.get_env ('PATH_MODULO', gv_path_log2);
    DBMS_SYSTEM.get_env ('FILELOG', v_file_log);
    DBMS_OUTPUT.put_line ( 'valores vars ORACLE_HOME: '
    || gv_path_log
    || 'PATH_MODULO:'
    || gv_path_log2
                   || ' FILELOG:'
                   || v_file_log
    gv_file_log :=
    v_file_log || TO_CHAR (SYSDATE, 'yyyymmddHH24MISS')
    || '.log';
    DBMS_OUTPUT.put_line ( 'Nombre de Archivo creado'
    || gv_path_log
    || ' '
    || gv_file_log
    gf_filelog := UTL_FILE.fopen (gv_path_log, gv_file_log, 'w');
    DBMS_OUTPUT.put_line ('Archivo creado' || gv_path_log || ' '
    || gv_file_log
    UTL_FILE.put_line (gf_filelog,
    || TO_CHAR (SYSDATE, 'HH24:MI:SSSSS')
    || ']--> '
    || 'Prueba de escritura'
    || gv_path_log
    || ' '
    || v_file_log
    UTL_FILE.fflush (gf_filelog);
    UTL_FILE.fclose (gf_filelog);
    EXCEPTION
    WHEN OTHERS
    THEN
    DBMS_OUTPUT.put_line ( '[reporta_log]Error en :'
    || SQLCODE
    || ' - '
    || SQLERRM
    raise_application_error (-20000,
    '[reporta_log]Error en :'
    || SQLCODE
    || ' - '
    || SQLERRM
    END;
    END;
    I show you data result after procedure was excecuted.
    obteniendo valores of vars:
    valores vars ORACLE_HOME: E:\oracle\product\10.2.0\db_1PATH_MODULO: FILELOG:
    Nombre de Archivo creadoE:\oracle\product\10.2.0\db_1 20111122171625.log
    [reporta_log]Error en :-29280 - ORA-29280: invalid directory path
    BEGIN
    ERROR at line 1:
    ORA-20000: [reporta_log]Error en :-29280 - ORA-29280: invalid directory path
    ORA-06512: at line 55
    I see that only ORACLE_HOME variable value was got, question is why, of course, variable values are already defined as user variables.
    Variables PATH_MODULO and FILELOG was defined using windows maintenance variable method, that is :
    1.- settings
    2.- system
    3.- advanced options
    4.- environment variables
    Here my oracle version
    SQL> select version from v$instance;
    VERSION
    10.2.0.1.0
    SQL>
    Is this an Oracle Issue or variables would be defined in another way?
    ORACLE_HOME VARIABLE was created when oracle engine was installed.
    I have got same result after computer was restart.
    I appreciate wathever clue.

    Ok, that is , I only can read environment variables values, but not variables values at user profile. It happends in unix environment too. So I tried to use another instruction sequence in order to read user variables values.
    Regards

  • Environment Variable Values

    Hi all,
    how do i get the environment variables in PL/SQL on Windows NT/2000 or SUN environment..?
    Thanks.

    hi Andrew P Clarke ,
    Thanks for ur immediate reply. That's fine, using sys_context. But i'm not asking thatt...sorrry i didn't specified clearly.
    My question is how do i get the Operating system - User defined system variables. (Ex: in Win 2000 Server Box i've creadted the sysvariable like TEST='C:\TEST\FILE\', like our V$parameter in ORACLE...in 'C'/JAVA we will use the function "GETENV".
    Similllar one in oracle. how do i get the value?
    Thank You very much for ur help and OTN.

  • How to get the path of the INST_TOP environment variable value

    Hi,
    I have some file processing code in the OAF. I would like to use INST_TOP/temp folder as a temporary location. When I tried to get the env variable from System.getenv(), System.getProperties(), they don't seem to have INST_TOP in the list.
    Could anyone please tell me if it could be fetched from some other place ?
    Thanks
    Ponraj

    Concurrent processes store the value in fnd_env_context ... if that helps, you might do something like the following (example only for this thread, not tested!):
    select value from FND_ENV_CONTEXT where variable_name = 'INST_TOP' and concurrent_process_id = (select max(concurrent_process_id) from FND_ENV_CONTEXT);
    Regards,
    Gareth

  • CLASSPATH Environment Variable on Win2k problem

    hi
    i am new to java, but having problems to seting the CLASSPATH Environment Variable on my Win2k professional. my university computers are alredy set and i enjoy working with java. i just cant get my head arround to this problem. it would be much appriciated if some one send me a link which provide screenshot to resolve this problem. i got my jdk1.4 kit in a folder caled jdk in c:\ root.
    thanks

    Ashwani_Saxena wrote:
    Our application is stand-alone application and we are using Applet with Object Id tag for JavaScript to Java connectivity. In our application we are displaying the value of classpath environment variable on screen.
    Applets and stand alone applications are two different animals.
    While migrating from JRE 1.5 to JRE 1.6, we are unable to retrieve the classpath variable value. After analyzing, figure out that when classpath is defined in uppercase (i.e. CLASSPATH) then only we are unable to retrieve its value. However if its defined in lower case or any character is in lower case (i.e. classpath) then its value appears correctly. We are retrieving the classpath value via the "Set" command from Java.
    That's completely unnecessary, there's a System.getevn("CLASSPATH") method.
    However the CLASSPATH environmental variable isn't much use, and certainly not in the case of Applets, which definitely don't use it.
    Futhermore I don't expect the sandbox environment of an Applet will allow you to access the environmental variables in any way, (certainly not by running a program). Applets, unless signed, have almost no access to the client machine they run on.

  • Reading Environment Variable

    Hi everybody
    I'm trying to read an environment variable value, but I don't know how to do it.
    Thanks.

    Five possibilities:
    -Don't use a env var for application values. Use a java property file instead.
    -Use System.getenv() on versions before 1.3.
    -Use the java command line option '-D' which makes the passed in value available via the system properties.
    -Use Runtime.exec() to run a OS specific command that returns the value and parse it.
    -Use JNI.

  • Using CIS to get UCM environment variables

    Hi,
    I am working on extending an existing CIS application.
    I would need to read the UCM's environment variable value.
    I see there are CIS APIs for the most common actions needed, but couldn't find anything useful in the docs - is there something similar for the env variables?
    Any help is highly appreciated.
    Thanks,
    Zoran

    Do you want to get the port and server name from the web server or from the database?
    If it's the web server have a look at the package OWA_Util.print_cgi_env to get a list (you can also run this procedure in the SQL Workshop) of all available environment variables in the HTTP session context. Use OWA_Util.get_env to read the value of a particular environment variable.
    Hope that helps
    Patrick

  • Windows Environment Variable

    Hey,
    I am trying to use
    cl_gui_frontend_services=>gui_download
    and include the windows environment variable %USERPROFILE%
    in the path for example:
    filename = '%USERPROFILE%/filename.txt'
    that only creates a directory called %USERPROFILE% but not the Variable.
    Has anybody experienced this ?
    Thank your for your help,
    kind Regards
    Christof

    you have to use the following code to get the environment variable value and then use that with gui_download
    call method cl_gui_frontend_services=>environment_get_variable
          exporting
            variable     = p_envir_name
          changing
            value        = ls_envir_path
          exceptions
            cntl_error   = 1
            error_no_gui = 2
            others       = 3.
    call method cl_gui_cfw=>flush
          exceptions
            cntl_system_error = 1
            cntl_error        = 2
            others            = 3.

  • How to Set Environment Variables in Windows

    Hi Guys,
    You know that we can retrieve the environment variables using System.getProperty("JAVA_HOME"); like this. It is easy.
    Can anyone tell me how to create an environment variable using System class or is there any alternate java API to create environment variable. Please let me know.
    My requirement is that I want to create the environment variable as follows
    DEV_HOME
    D:/Java/DEV

    Are you talking about Java System properties (get and set through System.get/setProperty) or Environment Variables (read-only, get through System.getenv)?
    You can set the former, not the latter (unless you start a new process through Runtime.exec(), for which you can specify a custom environment.

  • Unable to access value in System Environment Variable using Java

    I am using Java code to get the value of a System Environment Variable using the Runtime, Process java classes.
    The code works fine in tomcat, but when deployed in 9ias the code is unable to retrieve the value stored in the System environment variable in Windows 2000.

    Thanks for the comment steve, here is the code which i am using.
         public String getEnvironmentVariable()
                   // This will get the FEDREP_HOME environment variable
                   String FEDREP_HOME = null;
                   Process p = null;
                   Runtime rt = Runtime.getRuntime();
                        try {
                             // invokes a shell-command to retrieve FEDREP_HOME variable
                             String OS = System.getProperty("os.name").toLowerCase();
                                  // Get the Windows 95 environment variable
                                  if (OS.indexOf("windows 9") > -1)
                                            p = rt.exec( "command.com /c echo %FEDREP_HOME%" );
                                  // Get the Windows NT environment variable
                                  else if (OS.indexOf("nt") > -1)
                                            p = rt.exec( "cmd.exe /c echo %FEDREP_HOME%" );
                                  // Get the Windows 2000 environment variable
                                  else if (OS.indexOf("2000") > -1)
                                            p = rt.exec( "cmd.exe /c echo %FEDREP_HOME%" );
                                  // Get the Windows XP environment variable
                                  else if (OS.indexOf("xp") > -1)
                                            p = rt.exec( "cmd.exe /c echo %FEDREP_HOME%" );
                                  // Get the unix environment variable
                                  else if (OS.indexOf("linux") > -1)
                                            p = rt.exec( "sh -c echo $FEDREP_HOME" );
                                  // Get the unix environment variable
                                  else if (OS.indexOf("unix") > -1)
                                            p = rt.exec( "sh -c echo $FEDREP_HOME" );
                                  // Get the unix environment variable
                                  else if (OS.indexOf("sunos") > -1)
                                            p = rt.exec( "sh -c echo $FEDREP_HOME" );
                                  } else
                                            System.out.println("OS not known: " + OS);
                             // set up to read subprogram output
                             InputStream is = p.getInputStream();
                             InputStreamReader isr = new InputStreamReader(is);
                             BufferedReader br = new BufferedReader(isr);
                             // read output from subprogram
                             FEDREP_HOME = br.readLine();
                             br.close();
                        } catch(Exception ex)
                                  System.out.println("Error when getting FEDREP_HOME environment variable");
                                  ex.printStackTrace();
              return(FEDREP_HOME);

  • How do i get value of Environment variables from a java program?

    Hai,
    I have a setup file wherein i set the path for the root directory , in the following way.
    setenv TPEROOT "/home/systpe/khurram/changes"
    when i give echo $TPEROOT
    the path , home/systpe/khurram/changes , is displayed on the console
    If i want to assign the $TPEROOT to a string variable str in my java program , then how can i do it.
    I want to use the value of the environment variable in my program.
    Any help in this regard would be very useful
    Thanks
    khurram

    java -DTPEROOT=$TPEROOT myőackage.myclass myargs

  • Retrieve environment variables (but not classpath or other java ones..)

    Hi,
    Does somebody know another way than System.getPropriety() to retrieve a environment (system) variable? I have a variable so-called CSServer designing a path, and I do not succeed to retrieve it from a Java program.
    Any ideas?
    Thanks
    Richie

    I once implemented it by creating a process that executedecho %<yourVar>%and reading the output, but I'm not very proud of it.
    For other options, search the forums.
    Kind regards,
      Levi

  • Getting the value of a user defined environment variable

    hi,
    i have an environment variable called MY_PATH='E:\data'
    I am running a batch file which sets the value of this variable. Then i run my java program. Now from my java program i want the value of the variable MY_PATH. How do i get it?

    See http://developer.java.sun.com/developer/bugParade/bugs/4199068.html and http://developer.java.sun.com/developer/bugParade/bugs/4642629.html
    You can pass the value into the Java program as:
    $ java -DMY_PATH="E:\data" YourJavaProgram
    HTH,
    Binil

  • Customer Exit (i_step = 1) - Retrieve Variable Value

    Hello,
    I have BW web report and created customer exit (i_step = 1). The BW Web Report is being called from BSP application and I'm passing variable value on URL.
    For example:
    /sap/bw/BEx?cmd=ldoc&template_id=Z_JEFF_CLAIM_TEST&VAR_NAME_1=ZAGGET&VAR_VALUE_EXT_1=10310
    What I need to do now is retrieve the variable value passed on URL in the custom exit i_step = 1. 
    Does anyone know how to do this?
    Thanks,
    Gary

    hi Gary,
    can try in variable user exit ZXRSRU01 ?
    DATA: LOC_VAR_RANGE LIKE RRRANGEEXIT.
      IF I_STEP = 1.
        LOOP AT I_T_VAR_RANGE INTO LOC_VAR_RANGE WHERE VNAM = 'ZAGGET'.
        .... = LOC_VAR_RANGE-LOW.
        ENDLOOP. 
      ENDIF.
    hope this helps.

  • Getting a Unix environment variable

    Hi, everyone.
    I need to use a Unix enviroment variable from a form. This form
    is gonna use this variable in order to be the path of another
    form who is gonna be called.
    In other words:
    CALL_FORM( $unix_var + '/forms/myform_name' );
    unix_var is what I want to get.
    Thanks a lot in advance,
    Eduardo

    It worked, Michael. Thanks a lot!
    To the documentation guys at Oracle... This is how you define
    the TOOL_ENV package in the Forms' help:
    "The TOOL_ENV package allows you to interact with Oracle
    environment variables by retrieving their values for use in
    subprograms."
    Suggestion: ...with Oracle environment variables AND OTHER
    SYSTEM OPERATION ENVIRONMENT VARIABLES...
    because this narrow definition can prevent people for trying to
    use it to retrieve other NON-ORACLE environment variable via
    this package. Thanks.

Maybe you are looking for