Setting new environment variable on Linux

{noformat}I need to set new environment variable on my linux machine from inside my code. I am using csh and the command works fine from command line:
setenv IFConfigLocation4 /home/username/myfile.xml
But when i try the same thing from Java code it does not seem to have any effect. here is my code:
import java.util.*;
public class CDE_parser_methods{
public static String fileParse(String inFile, String parserName, String outFile, String CMConfig_locale)
String parsed = "SUCCESSFUL";
System.out.println("Parsing file..." + "\nParser name: " + parserName +"\nInput file name: " + inFile + "\nOutput file name: " + outFile + "\nCMConfig file is: " + CMConfig_locale);
System.out.println("Current Java version: " + System.getProperty("java.version"));
          String cmd[]={"/bin/csh", "-c", "setenv IFConfigLocation4 " + CMConfig_locale};
          Process proc = Runtime.getRuntime().exec(cmd);
          int exitVal= proc.waitFor();
          System.out.println("Value of setenv command is: " + exitVal);
          String cmd2[]={"/bin/csh", "-c", "env"};
          Process proc2 = Runtime.getRuntime().exec(cmd2);
          InputStream instr = proc2.getInputStream();
          InputStreamReader inread = new InputStreamReader(instr);
          BufferedReader buf = new BufferedReader(inread);
          String line=null;
          while((line=buf.readLine()) != null)
          int exitVal2= proc2.waitFor();
          }catch(CMException cme){
               System.out.println("Issue when trying to executing parse command, details: " + cme.getMessage());
               System.out.println("Description of the issue is: " + cme.getDescription());
               parsed = "FAILURE: " + cme.getDescription();
          }catch(Exception e){
               System.out.println("Uncought exception, details: " + e.getMessage());
               parsed = "FAILURE: " + e.getMessage();
     return parsed;
public static void main(String[] args) {
     String results=CDE_parser_methods.fileParse("/opt/itemfield/ServiceDB/Project2/Mapping_for_Account_Number_Structure_ITS_Input_File.xls","MappingforAccountNumberStructure","/opt/itemfield/ServiceDB/Project2/test_ws_44.xml","/home/rvenishe/CMConfig.xml");
     System.out.println("Result of fileParse call is: " + results);
     }The out put of my env command does NOT contain system variable "IFConfigLocation4". Any ideas? {noformat}

Environment variables and their values set from within a user process has their scope and lifetime limited to the process and its subprocesses. See java.lang.ProcessBuilder class and its API documentation for setting env for a subprocess that will be started by a ProcessBuilder instance. Even in the C programming we have the same limitation for the environment.
Since they are not globally set, system command like env or Java method like System.getenv() can't see them.

Similar Messages

  • Set DISPLAY environment variable -- in DBCA not working at AIX OS

    I want to create new database in AIX OS and database is oracle 10g:-
    When i say DBCA it is giving below error, what should i do?
    $ dbca
    DISPLAY not set.
    Set DISPLAY environment variable, then re-run.
    Please help...

    Pravin wrote:
    How to set the DISPLAY environment variable in AIX?Usual format is:
    export DISPLAY=
    Where the host is the hostname or IP address of the client platform running a X-Server. If the X-Server is running locally, then this entry can be omitted.
    The display-number is the display number of the X-Server to use. A single X-Server can have multiple displays. E.g. Unix server running a X-Server can have 10 users connected via X-Terminals and will this have 10 displays.
    Judging from X-Windows questions asked on OTN, it seems to be a tad complex to grasp for some - especially those from a MS Windows background as X-Windows is very different and also reverses the client-server concept, requiring the X-Server component to be running on the client platform (where the server platform runs the program that is the X-client).
    So it is a lot easier to rather use something like VNC instead - supported on most Unix platforms, Linux, Windows and Apple's OS/X.
    Simply run the VNC server on the server platform to create a virtual container for running the X-server display. Connect from a client using a VNC client.
    As it uses the RFB (Remote Frame Buffer) protocol, it is a lot faster than running the slower and larger X11 protocol required for X-Windows connectivity over TCP/IP.

  • How to set the Environment Variable

    I'm going through a tutorial on how to create an application and run from the command prompt. I have finished installing my jdk 6 Upadate 5 but i don't know how to set the Environment Variable for the javac compiler and the java interpreter to find my program.
    I have created an application called "ExampleProgram" and have saved it on drive C:. How do i set the Environment Variable so that the "javac" compiler and the "java" interpreter can find it

    gyesa_say wrote:
    I'm using Windows XP Service Pack 2.A very bad choice to go with Windows. Personally I prefer Linux.
    I Google and had several information on how set it, but i tried all of them and none seem to work.I typed "how to set environmental variable in winxp" in Google and the very first link provided all the information I needed (you need). These things will make much more sense if you go through it yourself rather than having someone else spoon-fed you the answer.

  • Environment Variables for Linux

    Hi All
    I am trying to set the Environement Variables on RHEL 5.2(64 Bit) for SM 7.0 Installation
    - I have installed the RPM "IBMJava2-AMD64-142-SDK-1.4.2-11.0.x86_64.rpm"
    - I have set the Environment Variable in .bash_profile file as below:
    export JAVA_HOME=/opt/IBMJava2-amd64-142
    expot PATH=$JAVA_HOME/bin:$PATH
    Logged out of root and logged in, but I am not able to see the correct JAVA -Version
    Its still showing the GNU version.
    Can you please let me know that was correct ?

    You can simply use those commands in the shell that is open and in which you want to start the installation. There's no need to make this permanent for user "root".
    Sapinst will configure the new users correctly with the correct PATH.

  • Setting Oracle environment variable using batch (.bat) file in windows

    Oracle 9i db
    Windows OS
    I am in process to create the database (Considered that Oracle9i software is already installed) by running one batch file which consist of all the scripts for the database creation.
    But i also want to set the environment variables at MyComputer(right click)>properties>advance>environment, permenently by running the batch (.bat) file
    So, how can it be done ?
    With Regards

    *@echo off*
    set ORACLE_SID=iprsdb
    set ORACLE_BASE=C:\oracle
    set ORACLE_HOME=C:\oracle\ora92     
    call C:\install_bkp\test_env_var.bat
    echo Test Successfull.
    Above mentioned is the code written in the batch (.bat) file
    In that i have also called another .bat file which test the env. variable values which is as below:
    Testing oracle sid
    Testing oracle base
    Testing oracle home
    Test Successfull.
    But when i checked at MyComputer(right click)>properties>advance>environment variables
    there, I saw none of the entries from the above, why so ?
    how to set env. variables permanently using the DOS commands. ?
    With Regards

  • Why do we actuallya need the setting of environment variables?

    Hello guys,
    I read that, in order to connect to the database via SQL*Plus, we need to have the environment variables set. So, SQL*Plus is a command tool, which doesnt know over which path to connect to db, if the environment variables are not set?
    How about the needs of setting environment variables at point of view of MS-DOS? I know that over MS-DOS we can check if the environment variables are already set or not. Or we can actively set the environment variables.
    When should we actually set the environment variables? Before we run the GUI or after? I read, that if we set it before we run the GUI, then the setting will be taken over when it comes to that step by running GUI. I am curious, since this would be interesting to know, if we use other version than XE.

    Oracle's flexibility ... many different versions working the same on many different versions of many different operating systems ... means that a single consistent installation and configuration methodology must work everywhere so as not to have the limitations of other competing products that work on only a single operating system or require that one learn a different syntax and methods for different versions.
    Be grateful Oracle is as it is. Your competence in one version and operating system translates into competence in others.

  • How to set ORACLE_HOME environment variables in win 2003

    Can anyone tell me how to set ORACLE_HOME environment variables in Win2003
    Please tell me the significance of that also.It will be really helpful if u can help me out from Path variable seting of JAVA SDK also... Thanks in advance...

    use this code IN FORMS60 variable in Regedit

  • Setting the environment variable

    I just installed the rpm for the 1.4 SDK on my RedHat 7.1 box. Does anyone know how I can set the environment variable so it will recognize Java from the command line? Thanks in advance.

    You need to set a couple of environment variables in your "profile" script. Which one, exactly, depends on the shell you use. It's probably .profile on your home directory.
    JAVA_HOME=/usr/java1.4 (or wherever it really is)
    export JAVA_HOME,PATH

  • I want to set Jdeveloper environment variables

    First,thanks for your answer.But I mean to set Jdevelop
    environment variables.If I can't set right Jdeveloper
    enironment,program can't pass the compile.Because "import
    oracle.html.*" can't be found by Jdeveloper.

    You would need to include jweb.jar file as a library in your
    project properties.
    jweb.jar comes with Oracle Application Server. Copy the jar file
    to lib directory in JDeveloper and add it as a library to the
    This would make import oracle.html.* work.
    Micheal Chang (guest) wrote:
    : First,thanks for your answer.But I mean to set Jdevelop
    : environment variables.If I can't set right Jdeveloper
    : enironment,program can't pass the compile.Because "import
    : oracle.html.*" can't be found by Jdeveloper.

  • Oracle Environment Variables on Linux

    First, I'll admit that I'm very, very new to Linux.  I'm running Oracle Database XE 11g R2 on a virtual machine (Virtualbox) that is running Oracle Enterprise Linux 6.  Whenever I open a terminal window and set ORACLE_HOME, PATH, and ORACLE_SID, I can easily access SQLPlus, simply by typing "SQLPlus".  However, if I close that window and then open another terminal window, I cannot access SQLPlus, simply by typing "SQLPlus".  I have to re-specify the environment variables first.
    I'm sure that this is something simple but my lack of Linux experience is keeping me from finding the issue.  Also, I've not found any documentation that helps but please point me to it if I've missed it.

    You can also set your environment by using a shell script that comes with the XE default installation:
    # source /u01/app/oracle/product/11.2.0/xe/bin/
    There's also a backup script.
    # /u01/app/oracle/product/11.2.0/xe/config/scripts/
    assuming that you've installed the XE instance in the default path /u01

  • Setting JAVA_HOME environment variable?

    Sorry for such a trivial question, but in Windows 2000 Server with Microsoft Visual J++ 6 and the JRK 1.1.8, can somebody tell me what the environment variables should be so that I can use this jdk? If not can you tell me what your environment variable JAVA_HOME points to?
    And one last question if it's not too much to ask. Can you tell me the NNTP server address for SUN so that I can go to the newsgroups in my News reader rather than over the web?
    George Hester

    Thanks. I have a problem though. I installed the jdk 1.1.8 because I heard that was the last one supported using Visual J++. Hence I have a C:\jdk1.1.8. This folder has no JRE subfolder so I am stuck at what you said the Classpath should contain as the path\folder you say it should be does not exist.
    I have a folder C:\Program Files\JavaSoft\JRE\1.3.1 which has the lib folder containing rt.jar.
    So as you can see I'm sort of in a quandry.
    If I make JAVA_HOME as you say then it does not contain the JRE. If I make JAVA_HOME C:\Program Files\JavaSoft so that your suggestion for Classpath is correct that folder does not contain the jrk and it seems that I will not be using it.
    Any suggestions how to set this up so that it's right?
    George Hester

  • How can I set PATH environment variables when there is no ~/.profile?

    I have a MacBook Air and just installed MySQL.
    I read the doc which I downloaded and should be able to run "mysql" from terminal as descibed below:
    Suppose that your MySQL programs are installed in /usr/local/mysql/bin and that you want to make it easy to invoke these programs. To do this, set the value of the PATH environment variable to include that directory. For example, if your shell is bash, add the following line to your .bashrc file:
    I checked on my terminal with ls -al, but no ~/.bashrc also no ~/.profile files.  Echo $SHELL shows me that I am using /bin/bash as shell.
    When I run export PATH=$PATH:/usr/local/mysql/bin  then it works and I just have to type "mysql" to get the mysql command line but as soon as I kill my terminal and open a new terminal this setting is lost.
    Any idea how I can accomplish this?

    Never mind, I found it :-)
    I just created a file  .bash_profile in my home folder and added "export PATH=$PATH:/usr/local/mysql/bin" and restarted my terninal. Now it works.

  • Setting widows environment variable like "path "

    I want to set a new value for windows environment variable path. Is there any way to set change the varibale.

    You could also use ORA_FFI package to call Windows API function SetEnvironmentVariable. There is an example below.
    See also:
    kernel_lhandle Ora_Ffi.Libhandletype;
    GetEnvironmentVariable_fhandle Ora_Ffi.Funchandletype;
    SetEnvironmentVariable_fhandle Ora_Ffi.Funchandletype;
    FUNCTION ff_GetEnvironmentVariable(
    fhandle Ora_Ffi.funchandletype,
    lpName varchar2,     -- address of environment variable name
    lpBuffer varchar2,     -- address of buffer for variable value
    nSize      pls_integer -- size of buffer, in characters
    ) RETURN pls_integer;
    PRAGMA interface( C, ff_GetEnvironmentVariable, 11265 );
    FUNCTION ff_SetEnvironmentVariable(
    fhandle Ora_Ffi.funchandletype,
    lpName varchar2,     -- address of environment variable name
    lpValue varchar2     -- address of variable value
    ) RETURN pls_integer;
    PRAGMA interface( C, ff_SetEnvironmentVariable, 11265 );
    function SetEnvironmentVariable(lpName varchar2, lpValue varchar2) return pls_integer IS
    return ff_SetEnvironmentVariable( SetEnvironmentVariable_fhandle, lpName, lpValue );
    function GetEnvironmentVariable(
    lpName varchar2
    ) return varchar2 as
    lpBuffer char(2000);     -- address of buffer for variable value
    nSize      pls_integer; -- size of buffer, in characters
    res pls_integer;
    nSize );
    if res>0 then
    return substr( lpBuffer, 1, res );
    return null;
    end if;
    -- Initialization
    /* Load the library */
    ( '', 'kernel32.dll' );
    /* GetEnvironmentVariable */
    ( kernel_lhandle, 'GetEnvironmentVariableA', Ora_Ffi.C_Std );
    ( GetEnvironmentVariable_fhandle, Ora_Ffi.C_CHAR_PTR );
    ( GetEnvironmentVariable_fhandle, Ora_Ffi.C_CHAR_PTR );
    ( GetEnvironmentVariable_fhandle, Ora_Ffi.C_INT );
    ( GetEnvironmentVariable_fhandle, Ora_Ffi.C_INT );
    /* SetEnvironmentVariable */
    ( kernel_lhandle, 'SetEnvironmentVariableA', Ora_Ffi.C_Std );
    ( SetEnvironmentVariable_fhandle, Ora_Ffi.C_CHAR_PTR );
    ( SetEnvironmentVariable_fhandle, Ora_Ffi.C_CHAR_PTR );
    ( SetEnvironmentVariable_fhandle, Ora_Ffi.C_INT );
    To change the variable PATH you could use something like the following code:
    s:=dll_path||';'||WIN32.GetEnvironmentVariable( 'PATH' );
    res:=WIN32.SetEnvironmentVariable( 'PATH', s );

  • Trouble Setting Windows Environment Variables

    My environment:
    Windows XP Professional
    Intellij 6.0.4
    JDK 1.4.
    I am seeing some very weird behavior when I try to get/set Environment Variables in Windows XP. I use the following code to read the variables:
    Process p = r.exec( "cmd.exe /c set" ); I create an environment varialbe through the Windows control panel, and it does not show up when I execute the above command. However, when I close my IDE and reopen it and run the same code, the variable appears. How is this possible? I am using the Windows XP cmd.exe in my program to read the variables. When I open a DOS window and type the same command, my variable is there.
    This is driving me crazy.
    i want my program to do some work, but then check a system variable to see if it should continue. I want a user to be able to stop processing by setting the environmen variable to true.

    Runtime.exec has a lot of overloadings. Two of them
    allows you to specify the environment variables.
    public Process exec(String[] cmdarray,
    String[] envp,
    File dir)
    throws IOExceptionExecutes the specified command and
    arguments in a separate process with the specified
    environment and working directory.
    cmdarray - array containing the command to call and
    its arguments.
    envp - array of strings, each element of which has
    environment variable settings in format name=value.
    dir - the working directory of the subprocess, or null
    if the subprocess should inherit the working directory
    of the current process.
    I had this sample program:
    public class SetVarExample {
    public static void main (String[] args) throws Exception {
         String[] cmd_env= new String[] {"password="+"ABCD","Path=C:\\Sun\\AppServer\\jdk\\bin"};
         String cmd = "cmd /c SET ";
    System.out.println( "Finish ...." );
    I tried it in a command prompt. But looks like when the program exits, it's a whole new process and so it does not retain the env variables set in the java program.
    Any suggestions? Am I doing it worng?

  • How to set timezone environment variable to EST

    Hello Experts
    I'm having problem when I try to run my Enterprise Manager. Listner start normaly but then I tries to start the database I got the following message.
    oracle@linux-f4y3:~> /apps/oracle/product/10.2.0/db_1/bin/emctl start dbconsole
    Oracle Enterprise Manager 10g Database Control Release
    Copyright (c) 1996, 2005 Oracle Corporation. All rights reserved.
    Timezone mismatch: The agentTZRegion value (EST) in
    does not match the current environment TZ setting(EST).
    The dbconsole cannot run with this mismatch.
    If EST is the correct timezone, set your timezone environment variable to EST and repeat the 'emctl start dbconsole' operation.
    If EST is not the correct timezone, make sure that the timezone in your environment is correct, and then run the following command in your local Oracle Home: 'emctl resetTZ agent'
    The output of this command will include detailed instructions to follow, to correct the mismatch.
    To me looks like I need to fix the timezone on my machine but I don't know how. Can please somebody shows me the steps how to achieve this task?
    Thanks a lot in advance.

    I believe this issue is occurring because timezone info between the OS and oracle is out of synch - possibly because timezone patches have been applied to the OS or oracle, but not both. It is always good practice to apply such patches to both OS and Oracle.
    Pl see these MOS Docs
    401834.1 - Problem: DST: Workaround to EM Agent Restart Problem Due to a Daylight Savings Change
    362888.1 - Problem: Startup Agent: EM Agent will not start due to Timezone mismatch (Daylight Savings changes for Australia)
    549079.1 - Troubleshooting Database Control Startup Issues

Maybe you are looking for

  • Satellite L305-S5894 hard disk failure?

    I've started getting this error pop-up suddenly and i'm not sure how to solve it. The computer still seems to be running just fine, but the pop-up continues coming every 5 minutes or so. Is there a way to fix this or must i buy a new hard disk? And i

  • My ipod touch keeps crashing and I need to recover it every time

    So this is the problem.. my ipod keep craching but a soft reset was all it needed. It used to happen every few weeks but now it's once or twice a week and once it's crashed, it goes in recovery mode. Now last time in an effort to isolate if it was a

  • How to get small nav images to resize

    I'm trying to get small images (~100x100 px) used for page navigation to resize in my CS6 responsive design. My CSS has width:auto and max-width:100%.  This works when images fill across the entire div, but these small ones, which are a fraction of t

  • Javac error, compiling

    I have never compiled a class file, and have just go this error, dose it mean that I stuffed up in my script or javac isnt workin properly. ________________________________________________dos_____________ C:/j2sdk1.4.1_03\bin>javac AV

  • Replacement magic mouse would not pair; need

    This problem is solved; am starting this discussion to maybe save someone time and trouble.  Problem began when I dropped my magic mouse and ended its life.  I was surprised it was that fragile but that is another story; I use is too much to give it