Problem reading environment variable in windows

Hi,
When I run this program,
env1 = "Console";
env2 = (System.getenv("SESSIONNAME"));
System.out.print(env1.length() + "/");
System.out.println(env2.length() + "/");
System.out.print(env2 + "/");
System.out.println(System.getenv("SESSIONNAME") + "/");
if (env1 == env2) System.out.println("identical");
    else  System.out.println("wrong"); I got this output
7/7/
Console/Console/
wrongWhen I type "set" in a Windows cmd box,
I have SESSIONNAME=Console
I don't see why env1 and env2 are different.
Do you know ?
Thanks,

O now, I made this mistake already found it myself, but this I did not think about, I
am sorry to post such a stupid problem !
and indeed this works, I can continue now.
     if ((System.getenv("SESSIONNAME").equals("Console"))) System.out.println("identical");
            else  System.out.println("wrong"); Thanks jverd !

Similar Messages

  • Problem reading Adobe Photoshop In Windows

    I have Windows 7; can't read .psd file; not a supported file type; need to work with layers. A solution to reading .psd files in Windows?

    Apologies. Will try Photoshop forum.
    Date: Tue, 13 Apr 2010 15:32:07 -0600
    From: [email protected]
    To: [email protected]
    Subject: Problem reading Adobe Photoshop In Windows
    Try the PhotoShop forum. However, you need to give information about the version of PhotoShop you have installed (assuming you were successful). If you do not have PhotoShop installed, then why ask the question. My point is that you have left a lot out of your post.
    >

  • How to read Environment Variable in Java.

    Hi,
    I am trying to read a environment variable $TMP which has a value of /apps/bea/pt847/psoft5/tmp in UNIX.
    I have written the following code and getting Null pointer exception when calling the method logmessage. Any help with reading environment variable is appreciated.
    public static void logMessage(String message) {
           SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss ");
           Date now = new Date();
           Properties p = null;   
           try
              p = getEnvVars("$TMP");
              System.out.println("the current value of TEMP is : " + p.getProperty("$TMP"));
           catch (Throwable e) {
              e.printStackTrace();
           try
           BufferedWriter os = new BufferedWriter(new FileWriter("/tmp/pscas_signon_log.txt", true));
           os.write(formatter.format(now));
           os.write(message);
           os.write("\n");
           os.write("tmp_env = " + p.getProperty("$TMP"));
           os.write("\n");
           os.close();
           catch(IOException _ex) { }
        public static Properties getEnvVars(String env_var) throws Throwable {
           Properties envVars = new Properties();
           Process p = Runtime.getRuntime().exec(env_var);
           BufferedReader br = new BufferedReader( new InputStreamReader( p.getInputStream() ) );
           String line = null;
           while( (line = br.readLine()) != null ) {
              int idx = line.indexOf( '=' );
              String key = line.substring( 0, idx );
              String value = line.substring( idx+1 );
              envVars.setProperty( key, value );
              // System.out.println( key + " = " + value );
           return envVars;
        }

    Updated code:
    public static void logMessage(String message) {
           SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss ");
           Date now = new Date();
           Properties p = null;   
           try
              p = getEnvVars("$TMP");
              System.out.println("the current value of TEMP is : " + System.getProperty("$TMP"));
           catch (Throwable e) {
              e.printStackTrace();
           try
           BufferedWriter os = new BufferedWriter(new FileWriter("/tmp/pscas_signon_log.txt", true));
           os.write(formatter.format(now));
           os.write(message);
           os.write("\n");
           os.write("tmp_env = " + System.getProperty("$TMP"));
           os.write("\n");
           os.close();
           catch(IOException _ex) { }
        public static Properties getEnvVars(String env_var) throws Throwable {
           Properties envVars = new Properties();
           Process p = Runtime.getRuntime().exec(env_var);
           BufferedReader br = new BufferedReader( new InputStreamReader( p.getInputStream() ) );
           String line = null;
           while( (line = br.readLine()) != null ) {
              int idx = line.indexOf( '=' );
              String key = line.substring( 0, idx );
              String value = line.substring( idx+1 );
              envVars.setProperty( key, value );
              // System.out.println( key + " = " + value );
           return envVars;
        }and this is the error message..
    java.io.IOException: $TMP: not found
            at java.lang.UNIXProcess.forkAndExec(Native Method)
            at java.lang.UNIXProcess.<init>(UNIXProcess.java:72)
            at java.lang.Runtime.execInternal(Native Method)
            at java.lang.Runtime.exec(Runtime.java:602)
            at java.lang.Runtime.exec(Runtime.java:461)
            at java.lang.Runtime.exec(Runtime.java:397)
            at java.lang.Runtime.exec(Runtime.java:359)
            at SimpleCasValidator.getEnvVars(SimpleCasValidator.java:108)
            at SimpleCasValidator.logMessage(SimpleCasValidator.java:81)

  • Problem with environment variables

    JAVA_HOME = C:\JBuilder9\jdk1.4
    Path = C:\oracle\product\10.1.0\Db_1\bin;C:\oracle\product\10.1.0\Db_1\jre\1.4.2\bin;C:\oracle\product\10.1.0\Db_1\jre\1.4.2\bin\client;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;.;C:\oracle1\product\10.1.0\Db_3\jdbc\lib\classes12.zip
    When I run foo.java I get this error, which i believe is because of some kind
    of problem with environment variables.
    Exception in thread "main" java.lang.NoClassDefFoundError: OraThinI eliminated this path
    C:\oracle\product\10.1.0\Db_1\jre\1.4.2\bin
    just to check whether two paths of jdk bin folder is causing problem but I see no change.
    Please help

    I had solved it myself
    I am a genious :P
    Just do this
    JAVA_HOME = C:\JBuilder9\jdk1.4
    CLASSPATH = C:\oracle\product\10.1.0\Db_1\jdbc\lib\classes12.zip;.;%JAVA_HOME%\bin
    PATH= C:\oracle\product\10.1.0\Db_1\bin;C:\oracle\product\10.1.0\Db_1\jre\1.4.2\bin;C:\oracle\product\10.1.0\Db_1\jre\1.4.2\bin\client;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;.;C:\oracle1\product\10.1.0\Db_3\jdbc\lib\classes12.zip;%JAVA_HOME%\bin

  • Jar file doesn't read classpath environment variable from windows xp

    I created a small program that uses javamail and jdbc driver. I program on Win XP and use java 1.6.04.
    When I compiled my classes the program works fine but when I created a jar package the jar file cannot 'see' the classpath that windows has already set.
    I have to set the classpath in the manifest file and then it works ok.
    Is this normal? I was expecting that the jar file would work just fine without any complication since the classpath is already set in the system?
    If you could point to any documentation that covers this it would be great.
    Thank you very much.
    Genti

    genti_tech wrote:
    I specified the class-path in manifest in jar file and I looked at the tutorial you are suggesting:
    http://java.sun.com/docs/books/tutorial/deployment/jar/
    which is not clear at all about the fact that jar ignores the class-path environment variable.It is specified for java. http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/java.html#-jar

  • Setting ORACLE_HOME as Environment variable in Windows

    Hi,
    I have a problem.
    I am using Oracle Application Server 9.0.4. on Windows 2000 server .
    There are 2 homes, one for mid tier and one for Infra.
    Now when I look in PATH variable of the environment variables, i can see both homes specified there.
    But when issue echo %ORACLE_HOME% from command prompt then i can see nothing.
    And there is no ORACLE_HOME environment variable, so i created a ORACLE_HOME variable and assigned the Oracle home path to it.
    Now when i issue the command echo %ORACLE_HOME% i can see the value of the ORACLE_HOME,
    So is this the correct way to set the ORACLE_HOME?
    Is this the way to create the ORACLE_HOME environment variable.
    Thanks & Regards,
    Avinash.
    Pune.
    India.

    So is this the correct way to set the ORACLE_HOME?
    Is this the way to create the ORACLE_HOMEenvironment
    variable.No. Not on Windows platforms.
    The Oracle Home paths are already set via Windows
    Resgistry values. Check HKLM\Software\Oracle\ (HOMEx
    or KEY_<home name>) for ORACLE_HOME settings.
    This is used by programs via PATH and when calling a
    program that uses the oracle.key files from OH\bin.
    Setting it via system environment could override
    individual settings, which may lead to unwanted
    results or issues.True for some areas.
    And yet, for Patching you MUST set the Oracle_Home variable, in which case Virag's response is the correct method.

  • Setting Environment variable in windows xp

    Hi all,
    I am trying to run a java program in textpad, which is installed in windows XP, but i am getting the following error.
    java.lang.NoSuchMethodError: main
    Exception in thread "main"
    Can anybody tell me, how to set the environment variable in the control panel.
    Thanx,
    Guddu

    java.lang.NoSuchMethodError: main
    Exception in thread "main"This error is NOT caused by an environmental variable mis-configuration. It means you did not define a main method correctly, or you are trying to run a class as an application and it is not an application.public static void main(String[] args)

  • Problem with environment variable & compiling

    G'day all,
    I'm totally confused :(
    I've set my environment detail but when I use javac the command window just does nothing. The cursor (or flashing thingo) drops to the line below and just hangs there. If i manually type in the entire path javac works fine.
    Image of my environment variable window is here:
    http://img130.imageshack.us/img130/5120/environvariables.jpg
    Using Windows 7, JDK 1.6.0_18 and latest version of Eclipse is installed.
    Second issue:
    I wrote a program using Eclipse. It all went into a package named "openagil". 3 classes in total. Class "A", "B", "C". A uses both B and C. It creates an instance of B and C. Included in each is package openagil; at the very top.
    Running in eclipse it works fine. However, how do I compile this using javac and then in turn run it? The .java files are located within a workbench folder (java) and then in the package directory (openagil). These are contained on the D drive so "d:\java\openagil" - No class variables are set as I am unsure how this is done (despite reading a few guides).
    I can do javac d:\...*.java and it'll compile all of them fine but I am then unsure how to run it. I think what I do is do java openagil.classA but this pulls up errors - an "exception in thread' error followed by a "noclassdeffound: openagil/classA" then a whole bunch of URL/Access Controller stuff.
    I understand programming fine, but configuring this is a bitch. My Java book doesn't cover installation nor does it cover packages and the

    LordMidol wrote:
    Second issue:
    I wrote a program using Eclipse. It all went into a package named "openagil". 3 classes in total. Class "A", "B", "C". A uses both B and C. It creates an instance of B and C. Included in each is package openagil; at the very top.
    Running in eclipse it works fine. However, how do I compile this using javac and then in turn run it? The .java files are located within a workbench folder (java) and then in the package directory (openagil). These are contained on the D drive so "d:\java\openagil" - No class variables are set as I am unsure how this is done (despite reading a few guides).
    I can do javac d:\...*.java and it'll compile all of them fine but I am then unsure how to run it. I think what I do is do java openagil.classA but this pulls up errors - an "exception in thread' error followed by a "noclassdeffound: openagil/classA" then a whole bunch of URL/Access Controller stuff.You need to us the -classpath (or -cp) command line option to specify where java looks for your .class files. I think it would be java -cp d:\java openagil.classAFYI class naming convention is to start with a capital letter - YourMainClass for example. It may help to go here [http://java.sun.com/javase/6/docs/technotes/tools/index.html] and go to General Information, then click on How Classes Are Found.

  • Within JBuilder, Reading Environment Variable From a BATCH File

    Hi ppl:
    Following my scenario without JBuilder. I would like to be able to do the same with JBuilder, so that I can run my application from within.
    1. In the DOS window, I run a config.bat file that sets up a whole bunch of environment variables and then calls another script file that sets up another whole bunch to set up environment for a third party API (C++ based).
    2. My application uses native methods to call the third party API which uses the environment variables set in step 1.
    I know how to set the environment varialbes in JBuilder (Project Parameters, VM). However, I don't know how I can call a batch file that does the same. I don't want to set up the third party variables in JBuilder manually, since the script that sets them up checks on a few things to customize the environment.
    I also know how to run a batch file from JBuilder, but that does not set the environment for the application. It seems like the batch file is run in a separate process.
    Any ideas?
    Kamran

    It seems like the batch file is run in a separate process.Yes, it is. That's a design feature of Windows. The environment variables that a process creates are available to any subprocess, but when the process ends, the environment variables vanish. That's because they are part of the process, not global variables as you might wish.
    So that's why your non-JBuilder scenario works; your C++ program is running in a subprocess of the process that defined the environment variables. And your JBuilder scenario doesn't work because the batch file it runs is in a process whose parent process is Windows, not JBuilder.

  • R12, Environment Variables on Windows, and OBIEE

    Dear Experts,
    I've managed to install R12 on Windows.
    Now, in the global environment variable, Path, the user Oracle has a number of directories in its default PATH, starting with the Oracle apps middle tier.
    C:\oapps\apps\tech_st\10.1.2\bin;     
    C:\oapps\apps\tech_st\10.1.2\jdk\jre\bin\classic;     
    C:\oapps\apps\tech_st\10.1.2\jdk\jre\bin;
    C:\oapps\apps\tech_st\10.1.2\jlib;     
    C:\oapps\apps\tech_st\10.1.3\bin;     
    C:\oapps\db\tech_st\11.1.0\bin;     
    C:\Windows\system32;     
    C:\Windows;     
    I notice that there are .cmd scripts that set the Path.
    This script sets the path to look in: c:\oapps\db
    cd C:\oapps\db\tech_st\11.1.0
    VIS_black.cmd
    echo %PATH%
    C:\oapps\db\tech_st\11.1.0\perl\5.8.3\bin\MSWin32-x86-multithread\;
    C:\oapps\db\tech_st\11.1.0\bin;
    This script sets the path to look in: c:\oapps\apps
    set PATH=""
    cd c:\oapps\apps\apps_st\appl
    VIS_black.cmd
    echo %PATH%
    C:\oapps\apps\apps_st\appl\au\12.0.0\bin;
    I'd like to install OBIEE on the same server. Obviously, I don't want any path conflicts. And, OBIEE uses a different version of java.
    1)
    Do all these Apps directories need to remain in the global PATH environment variable? Or, can the directories be removed from the path, and the scripts can be relied on to set the appropriate variables?
    Thanks a lot!

    if you want global settings (always present, even after reboot), you have to edit the autoexec.bat file, e..g
    SET CLASSPATH=c:\myclasses
    you can set environment variables temporarility in a DOS shell using the same command.
    if possible, you should avoid the CLASSPATH environment variable, and use the -cp or -classpath option for java and javac. This helps a lot to solve classpath confusions.

  • Problem with ENVIRONMENT VARIABLES in MS-DOS

    I have just installed JDK & J2EESDK under the directory C:\Program Files.
    I set my JAVA_HOME to C:\Program Files\jdkblahblah\bin
    and J2EE_HOME to C:\Program Files\j2eesdkblahblah\bin
    and CLASSPATH to %J2EE_HOME%\lib\j2ee.jar
    As you may have noticed there is a space in the directory "Program Files" and this has been giving me a lotta problems. When i try to run any batch files it doesn't recognise the classpath...Same thing happens when i try to run javac with the -classpath option.
    Even when i use full path names instead of env.variables it still has problems as it is assuming the latter part after the space(Files\j2ee..) and the one before the space(C:\Program) as two different paths....
    How do i fix this? I have a work-around but, I would like to know how to fix this thing...

    I guess that surrounding the path with quotes might help. You have windoze on your 'puter, haven't you. In case of Win2K, right click on "my computer", select "properties", select "special", and then "environment variables". There you may edit the PATH. I guess editing the classpath is also a must.
    Or, alternatively, uninstall java, and reinstall it in the root directory, without having white spaces in the path. Makes your life much easier...

  • Help: reading environment variables?

    Hi! I'm working with node.js in EB3 and am running into a little problem- I have a few environment variables that I want to use (set in .profile and already working in standalone applications). But if I try to read them using process.env.XYZ as usual, they turn up undefined. What am I missing?

    Yes. Checking process.env shows any environment variables that are defined at runtime, as well as PATH, USER, SHELL, etc. Any that I've defined elsewhere don't show up, even if they are exposed as expected to other applications. I've tried exporting from .profile, .bashrc and .bash_profile so far with no changes. Thanks, though- hopefully I'll have an aha moment soon!
    Found a solution via stackexchange: apparently some users have this problem with GUI applications on newer versions of OS X, and the workaround is to set variables in a terminal session and launch the application there. Which defeats the purpose in my case but hope it's useful to someone else!

  • 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.

  • How to read environment variable

    How do I read an environment variable within TS?
    I was thinking of calling getenv("VARIABLE_NAME") except it returns a char * and TS only allows Boolean or Numeric return type.
    I wonder if LV has any function for doing the same thing. 

    With the new ability in TestStand 4.2 to get the standard output from a command line, you can do this with a call executable step.
    Simply call cmd.exe as the executable, and pass it the following expression.  Then all you have to do is set Locals.EnvironmentVariableName to the name of the environment variable you want the value of and define where you want the standard output to be stored.
    "/C \"echo %"+Locals.EnvironmentVariableName+"%\""
    I'm attaching a sequence file that shows this.  The attachment is necessarily saved in TestStand 4.2, since it uses a feature introduced in that version.
    Josh W.
    Certified TestStand Architect
    Formerly blue
    Attachments:
    get env var.seq ‏6 KB

  • How can I reading environment variables (user variables)

    Hi,
    I hope someone can halp me out:
    In the software that I develop it is neccessary to read some user (environment) variables, such as the temp folder of the current user.
    I know that I can read out some system variables like this:
    String homePath = System.getProperty("user.home");
    But how can I read out some other variables, especially the temp folder of the current user?
    Thanks

    I might have misunderstood you, but I am notlooking
    for the PATH variable. I need the location of
    the
    temp folder of the current user. This should be
    called TEMP or so, but this does not work.Can you deduce from the link he provided, to lookat
    System.getenv(), and find the "TEMP" environment
    variable in what it returns to you?That said, I believe the "temp" folder may be
    provided in one of the normal System properties
    anyway, so you probably don't need to go that route.
    Print all your System.getProperties() values, and see
    if it's in there.Yepp. os.io.temp or something.

Maybe you are looking for

  • Keeps asking for keychain password

    I just upgraded to Mac Pro and Leopard--I transferred files by means of migration assistant and everything went well, but every time I restart of log in safari is asking me for my keychain password. How do I turn this off? Thanx,

  • Anyway to smooth out a progress bar?

    I'm using a Timer with an event to update data on a page.  I'm also using a progress bar to indicate the next update (every 30 seconds).  Currently I'm using a manual progress bar with setProgress() to increase the value by 1 (max value 30) every sec

  • NVIDIA and M-PAL, what shame...

    I just purchase one MSI G4MX460-VTP. I choose this card because your great features, like video capture and TV out. But the WDM drivers don't have the M-PAL option. I'm Brazilian and the video standard in my country is M-PAL. Exists any solution? If

  • Garage Band suddenly won't open projects

    I have been using Gaage Band with success for a while and have a number of projects saved. Today I went to open a previous project, but it wouldn't open. I could see all of the project names on the file list, I just couldn't click on them to open the

  • OIM Install on WebSphere

    Trying to install OIM on SUSE10/ WebSphere... getting this error RIGHT at the end of the install, after the progress bar, after creating uninstaller: Anyone recognize this? Thanks so much Alex Finalizing Vital Product Data Registry... sun.io.Malforme