PATH Environment Variable Is Not Displayed For JVM IN The Database (Doc ID 438906.1)

Last updated on JULY 09, 2012

Applies to:

Oracle Server - Enterprise Edition - Version 10.2.0.3 to 11.2.0.2 [Release 10.2 to 11.2]
Information in this document applies to any platform.

Symptoms

-- Problem Statement:
On 10.2.0.3.0:
This block of code returns a valid value on the PATH variable in 8.1.7.4. In 10.2.0.3, it returns
PATH=<null>

declare
  p_date varchar2(30);
  l_output DBMS_OUTPUT.chararr;
  l_lines INTEGER := 1000;

begin
  DBMS_OUTPUT.enable(1000000);
  DBMS_JAVA.set_output(1000000);

  select trim(to_char(sysdate,'YYYYMMDDHH24MISS')) into p_date from dual;

  CIP_COMMAND('set');

  DBMS_OUTPUT.get_lines(l_output, l_lines);

  FOR i IN 1 .. l_lines LOOP
    dbms_output.put_line('line' || to_char(i) || '-' || l_output(i));
  END LOOP;

end;
/


Output:

line1-Process out
:CLASSPATH=/apps/oracle/product/10.2.0/db_1/jlib:/apps/oracle/product/jlib
line2-Process out :EDITOR=/usr/bin/vi
line3-Process out :HOME=/export/home/oracle
line4-Process out :HZ=100
line5-Process out :IFS=
line6-Process out :
line7-Process out
:LD_LIBRARY_PATH=/apps/oracle/product/10.2.0/db_1/dbjava/lib:/usr/lib:/apps/orac
le/product/10.2.0/db_1/lib:/usr/java/lib:/usr/java/jre/lib/sparc
line8-Process out :LOGNAME=oracle
line9-Process out :MAIL=/var/mail/oracle
line10-Process out :MAILCHECK=600
line11-Process out :OPTIND=1
line12-Process out :ORACLE_BASE=/apps/oracle
line13-Process out :ORACLE_HOME=/apps/oracle/product/10.2.0/db_1
line14-Process out :ORACLE_OWNER=oracle
line15-Process out :ORACLE_SID=ezpwebt
line16-Process out :ORACLE_SPAWNED_PROCESS=1
line17-Process out :ORACLE_TERM=vt100
line18-Process out :ORA_NET2_DESC=9,12
Here is the problem =======================================> line19-Process out :PATH=
line20-Process out :PWD=/export/home/oracle
line21-Process out :SHELL=/bin/ksh
line22-Process out :TERM=vt100
line23-Process out :TNS_ADMIN=/apps/oracle/product/10.2.0/db_1/network/admin
line24-Process out :TZ=EST5EDT
line25-Process out :_=/apps/oracle/product/10.2.0/db_1/bin/sqlplus



EXPECTED BEHAVIOR
It should have the correct value as in the 8.1.7.4 database.

-- Steps To Reproduce:
The issue can be reproduced at will with the following steps:

1. Create the next java code in the database:

CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "CIPHost" AS
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class CIPHost
{
  public static void executeCommand(String command)
  {
    try
    {
      String[] finalCommand;
      if (isWindows())
      {
        finalCommand = new String[4];
        finalCommand[0] = "C:\\windows\\system32\\cmd.exe";
        finalCommand[1] = "/y";
        finalCommand[2] = "/c";
        finalCommand[3] = command;
      }
      else
      {
        finalCommand = new String[3];
        finalCommand[0] = "/bin/sh";
        finalCommand[1] = "-c";
        finalCommand[2] = command;
      }

      final Process pr = Runtime.getRuntime().exec(finalCommand);
      new Thread(new Runnable()
      {
        public void run()
        {
          try
          {
            BufferedReader br_in = new BufferedReader(new
            InputStreamReader(pr.getInputStream()));
            String buff = null;
            while ((buff = br_in.readLine()) != null)
            {
              System.out.println("Process out :" + buff);
              try
              {
                Thread.sleep(100);
              }
              catch (Exception e)
              {
              }
            }
            br_in.close();
          }
          catch (IOException ioe)
          {
            System.out.println("Exception caught printing process output.");
            ioe.printStackTrace();
          }
        }
      }).start();

      new Thread(new Runnable()
      {
        public void run()
        {
          try
          {
            BufferedReader br_err = new BufferedReader(new
            InputStreamReader(pr.getErrorStream()));
            String buff = null;
            while ((buff = br_err.readLine()) != null)
            {
              System.out.println("Process err :" + buff);
              try
              {
                Thread.sleep(100);
              }
              catch (Exception e)
              {
              }
            }
            br_err.close();
          }
          catch (IOException ioe)
          {
            System.out.println("Exception caught printing process error.");
            ioe.printStackTrace();
          }
        }
      }).start();
    }
    catch (Exception ex)
    {
      System.out.println(ex.getLocalizedMessage());
    }
  }

  public static boolean isWindows()
  {
    if (System.getProperty("os.name").toLowerCase().indexOf("windows")!=-1)
      return true;
    else
      return false;
  }
};
/



2. Create the next wrapper for the java code created before:

CREATE OR REPLACE PROCEDURE CIP_Command (p_command IN VARCHAR2)
AS LANGUAGE JAVA
NAME 'CIPHost.executeCommand (java.lang.String)';
/



3. Grant the required privileges to the user who is running this java code (for this case MIKE):

EXEC DBMS_JAVA.grant_permission('MIKE', 'java.io.FilePermission', '<>',
'read,write, execute, delete');
EXEC Dbms_Java.Grant_Permission('MIKE',
'SYS:java.lang.RuntimePermission','writeFileDescriptor', '');
EXEC Dbms_Java.Grant_Permission('MIKE',
'SYS:java.lang.RuntimePermission','readFileDescriptor', '');



4. Run the next plsql code to call the java stored procedure:

set serveroutput on

declare
  p_date varchar2(30);
  l_output DBMS_OUTPUT.chararr;
  l_lines INTEGER := 1000;
begin
  DBMS_OUTPUT.enable(1000000);
  DBMS_JAVA.set_output(1000000);

  select trim(to_char(sysdate,'YYYYMMDDHH24MISS')) into p_date from dual;

  CIP_COMMAND('set');

  DBMS_OUTPUT.get_lines(l_output, l_lines);

  FOR i IN 1 .. l_lines LOOP
    dbms_output.put_line('line' || to_char(i) || '-' || l_output(i));
  END LOOP;
end;
/


The PATH variable is empty.


Cause

Sign In with your My Oracle Support account

Don't have a My Oracle Support account? Click to get started

My Oracle Support provides customers with access to over a
Million Knowledge Articles and hundreds of Community platforms