<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Stored Java to run an OS command, copy a file and get a directory listing in Oracle</title>
	<atom:link href="http://technology.amis.nl/2005/02/11/stored-java-to-run-an-os-command-copy-a-file-and-get-a-directory-listing/feed/" rel="self" type="application/rss+xml" />
	<link>http://technology.amis.nl/2005/02/11/stored-java-to-run-an-os-command-copy-a-file-and-get-a-directory-listing/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=stored-java-to-run-an-os-command-copy-a-file-and-get-a-directory-listing</link>
	<description></description>
	<lastBuildDate>Fri, 12 Apr 2013 10:04:09 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
	<item>
		<title>By: swetha</title>
		<link>http://technology.amis.nl/2005/02/11/stored-java-to-run-an-os-command-copy-a-file-and-get-a-directory-listing/#comment-1708</link>
		<dc:creator>swetha</dc:creator>
		<pubDate>Thu, 04 Sep 2008 22:49:09 +0000</pubDate>
		<guid isPermaLink="false">/?p=394#comment-1708</guid>
		<description><![CDATA[We are trying to do similar as explained by you. We want to execute &quot;java -jar &quot;C:\\Documents and Settings\\skulkar\\Desktop\\TestExec.jar\&quot; &quot; through Runtime.getRuntime().exec(); but always ending error - java doesn&#039;t exist ... do i need to provide some permissions for PL/SQL to understand the java command ? Please advice]]></description>
		<content:encoded><![CDATA[<p>We are trying to do similar as explained by you. We want to execute &#8220;java -jar &#8220;C:\\Documents and Settings\\skulkar\\Desktop\\TestExec.jar\&#8221; &#8221; through Runtime.getRuntime().exec(); but always ending error &#8211; java doesn&#8217;t exist &#8230; do i need to provide some permissions for PL/SQL to understand the java command ? Please advice</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Manju</title>
		<link>http://technology.amis.nl/2005/02/11/stored-java-to-run-an-os-command-copy-a-file-and-get-a-directory-listing/#comment-1707</link>
		<dc:creator>Manju</dc:creator>
		<pubDate>Thu, 15 Mar 2007 04:49:22 +0000</pubDate>
		<guid isPermaLink="false">/?p=394#comment-1707</guid>
		<description><![CDATA[Hi

Is there any way to call the AcroRd .exe from this program .since the program uses the Process  class i thought is workable .but the pc hangs
Please advice

Thanks]]></description>
		<content:encoded><![CDATA[<p>Hi</p>
<p>Is there any way to call the AcroRd .exe from this program .since the program uses the Process  class i thought is workable .but the pc hangs<br />
Please advice</p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kenny</title>
		<link>http://technology.amis.nl/2005/02/11/stored-java-to-run-an-os-command-copy-a-file-and-get-a-directory-listing/#comment-1706</link>
		<dc:creator>Kenny</dc:creator>
		<pubDate>Thu, 30 Nov 2006 03:22:06 +0000</pubDate>
		<guid isPermaLink="false">/?p=394#comment-1706</guid>
		<description><![CDATA[This was a great tip! I followed all the steps and was able to invoke a shell script from Stored java on the database. However, the script that gets invoked runs some commands such as touch files and `date`. The script runs and then stops at the first place where it gets to such a command. It does not give me any error messages. I am positive that the script is actually running. I have changed permissions on everything to allow access, so I am sure that is not it either. Any ideas?]]></description>
		<content:encoded><![CDATA[<p>This was a great tip! I followed all the steps and was able to invoke a shell script from Stored java on the database. However, the script that gets invoked runs some commands such as touch files and `date`. The script runs and then stops at the first place where it gets to such a command. It does not give me any error messages. I am positive that the script is actually running. I have changed permissions on everything to allow access, so I am sure that is not it either. Any ideas?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: GURWINDER SINGH</title>
		<link>http://technology.amis.nl/2005/02/11/stored-java-to-run-an-os-command-copy-a-file-and-get-a-directory-listing/#comment-1705</link>
		<dc:creator>GURWINDER SINGH</dc:creator>
		<pubDate>Tue, 14 Nov 2006 22:16:39 +0000</pubDate>
		<guid isPermaLink="false">/?p=394#comment-1705</guid>
		<description><![CDATA[i have done above steps ,all are working fine but on last step
 i received error SQL&gt;  exec rc(&#039;C:WINDOWSsystem32cmd.EXE /c dir C:SCOTT&#039;)
BEGIN rc(&#039;C:WINDOWSsystem32cmd.EXE /c dir C:SCOTT&#039;); END;

*
ERROR at line 1:
ORA-06501: PL/SQL: program error
ORA-06512: at &quot;SCOTT.RC&quot;, line 10
ORA-06512: at line 1
steps

please help.I will be verythankful to you for this


1.) create or replace type STRARRAY as table of varchar2(255)
    /

2.)CREATE OR REPLACE PACKAGE UTIL AS
 FUNCTION RUN_CMD(p_cmd IN VARCHAR2) RETURN NUMBER;
 PROCEDURE COPY_FILE(p_srcFile IN VARCHAR2, p_destDir IN VARCHAR2);
 PROCEDURE GET_DIR_LIST(p_dir IN VARCHAR2, p_dirList OUT STRARRAY);
END UTIL;
/

3.)CREATE OR REPLACE PACKAGE BODY UTIL AS
 FUNCTION RUN_CMD(p_cmd IN VARCHAR2) RETURN NUMBER
  AS LANGUAGE JAVA NAME &#039;nl.amis.util.RunCmd.runThis(java.lang.String) return int&#039;;
 PROCEDURE COPY_FILE(p_srcFile IN VARCHAR2, p_destDir IN VARCHAR2)
  AS LANGUAGE JAVA NAME &#039;nl.amis.util.FileCopy.copy(java.lang.String, java.lang.String)&#039;;
 PROCEDURE GET_DIR_LIST(p_dir IN VARCHAR2, p_dirList OUT STRARRAY)
  AS LANGUAGE JAVA NAME &#039;nl.amis.util.DirList.getList(java.lang.String, oracle.sql.ARRAY[])&#039;;
END UTIL;
/
4.)
CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED &quot;RunCmd&quot; AS
package nl.amis.util;

import java.io.*;

public class RunCmd
{
  private static void pass( java.lang.String p_in,
                         java.lang.String[] p_out )
  {
    if ( p_in != null ){
        p_out[ 0 ] = p_in.toUpperCase();
    }
  }

  public static int runThis(String cmd)
  {
    Runtime rt = Runtime.getRuntime();
    int        rc = -1;

    String[] args = new String[ 4096 ];
    pass(cmd, args);

    try
    {
       Process p = rt.exec(args[ 0 ]);

       int bufSize = 4096;
       BufferedInputStream bis =
        new BufferedInputStream(p.getInputStream(), bufSize);
       int len;
       byte buffer[] = new byte[bufSize];

       // Echo back what the program spit out
       while ((len = bis.read(buffer, 0, bufSize)) != -1)
          System.out.write(buffer, 0, len);

       rc = p.waitFor();
    }
    catch (Exception e)
    {
       e.printStackTrace();
       rc = -1;
    }
    return rc;
  }
}
/
5.)BEGIN
  dbms_java.grant_permission( &#039;scott&#039;, SYS:java.io.FilePermission&#039;, &#039;C:WINDOWSSYSTEM32CMD.EXE&#039;, &#039;execute&#039; );
  dbms_java.grant_permission( &#039;scott&#039;, &#039;SYS:java.lang.RuntimePermission&#039;, &#039;*&#039;, &#039;writeFileDescriptor&#039; );
END;
/

6.)CREATE OR REPLACE PROCEDURE RC(
   P_CMD IN VARCHAR2)
AS
   X                             NUMBER;
BEGIN
   X := UTIL.RUN_CMD (P_CMD);

   IF (X  0)
   THEN
      RAISE PROGRAM_ERROR;
   END IF;
END RC;
/
7.)SQL&gt; set serveroutput on size 1000000
SQL&gt; exec dbms_java.set_output(1000000)

PL/SQL procedure successfully completed.

8.)
SQL&gt;  exec rc(&#039;C:WINDOWSsystem32cmd.EXE /c dir C:SCOTT&#039;)
BEGIN rc(&#039;C:WINDOWSsystem32cmd.EXE /c dir C:SCOTT&#039;); END;

*
ERROR at line 1:
ORA-06501: PL/SQL: program error
ORA-06512: at &quot;SCOTT.RC&quot;, line 10
ORA-06512: at line 1]]></description>
		<content:encoded><![CDATA[<p>i have done above steps ,all are working fine but on last step<br />
 i received error SQL&gt;  exec rc(&#8216;C:WINDOWSsystem32cmd.EXE /c dir C:SCOTT&#8217;)<br />
BEGIN rc(&#8216;C:WINDOWSsystem32cmd.EXE /c dir C:SCOTT&#8217;); END;</p>
<p>*<br />
ERROR at line 1:<br />
ORA-06501: PL/SQL: program error<br />
ORA-06512: at &#8220;SCOTT.RC&#8221;, line 10<br />
ORA-06512: at line 1<br />
steps</p>
<p>please help.I will be verythankful to you for this</p>
<p>1.) create or replace type STRARRAY as table of varchar2(255)<br />
    /</p>
<p>2.)CREATE OR REPLACE PACKAGE UTIL AS<br />
 FUNCTION RUN_CMD(p_cmd IN VARCHAR2) RETURN NUMBER;<br />
 PROCEDURE COPY_FILE(p_srcFile IN VARCHAR2, p_destDir IN VARCHAR2);<br />
 PROCEDURE GET_DIR_LIST(p_dir IN VARCHAR2, p_dirList OUT STRARRAY);<br />
END UTIL;<br />
/</p>
<p>3.)CREATE OR REPLACE PACKAGE BODY UTIL AS<br />
 FUNCTION RUN_CMD(p_cmd IN VARCHAR2) RETURN NUMBER<br />
  AS LANGUAGE JAVA NAME &#8216;nl.amis.util.RunCmd.runThis(java.lang.String) return int&#8217;;<br />
 PROCEDURE COPY_FILE(p_srcFile IN VARCHAR2, p_destDir IN VARCHAR2)<br />
  AS LANGUAGE JAVA NAME &#8216;nl.amis.util.FileCopy.copy(java.lang.String, java.lang.String)&#8217;;<br />
 PROCEDURE GET_DIR_LIST(p_dir IN VARCHAR2, p_dirList OUT STRARRAY)<br />
  AS LANGUAGE JAVA NAME &#8216;nl.amis.util.DirList.getList(java.lang.String, oracle.sql.ARRAY[])&#8217;;<br />
END UTIL;<br />
/<br />
4.)<br />
CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED &#8220;RunCmd&#8221; AS<br />
package nl.amis.util;</p>
<p>import java.io.*;</p>
<p>public class RunCmd<br />
{<br />
  private static void pass( java.lang.String p_in,<br />
                         java.lang.String[] p_out )<br />
  {<br />
    if ( p_in != null ){<br />
        p_out[ 0 ] = p_in.toUpperCase();<br />
    }<br />
  }</p>
<p>  public static int runThis(String cmd)<br />
  {<br />
    Runtime rt = Runtime.getRuntime();<br />
    int        rc = -1;</p>
<p>    String[] args = new String[ 4096 ];<br />
    pass(cmd, args);</p>
<p>    try<br />
    {<br />
       Process p = rt.exec(args[ 0 ]);</p>
<p>       int bufSize = 4096;<br />
       BufferedInputStream bis =<br />
        new BufferedInputStream(p.getInputStream(), bufSize);<br />
       int len;<br />
       byte buffer[] = new byte[bufSize];</p>
<p>       // Echo back what the program spit out<br />
       while ((len = bis.read(buffer, 0, bufSize)) != -1)<br />
          System.out.write(buffer, 0, len);</p>
<p>       rc = p.waitFor();<br />
    }<br />
    catch (Exception e)<br />
    {<br />
       e.printStackTrace();<br />
       rc = -1;<br />
    }<br />
    return rc;<br />
  }<br />
}<br />
/<br />
5.)BEGIN<br />
  dbms_java.grant_permission( &#8216;scott&#8217;, SYS:java.io.FilePermission&#8217;, &#8216;C:WINDOWSSYSTEM32CMD.EXE&#8217;, &#8216;execute&#8217; );<br />
  dbms_java.grant_permission( &#8216;scott&#8217;, &#8216;SYS:java.lang.RuntimePermission&#8217;, &#8216;*&#8217;, &#8216;writeFileDescriptor&#8217; );<br />
END;<br />
/</p>
<p>6.)CREATE OR REPLACE PROCEDURE RC(<br />
   P_CMD IN VARCHAR2)<br />
AS<br />
   X                             NUMBER;<br />
BEGIN<br />
   X := UTIL.RUN_CMD (P_CMD);</p>
<p>   IF (X  0)<br />
   THEN<br />
      RAISE PROGRAM_ERROR;<br />
   END IF;<br />
END RC;<br />
/<br />
7.)SQL&gt; set serveroutput on size 1000000<br />
SQL&gt; exec dbms_java.set_output(1000000)</p>
<p>PL/SQL procedure successfully completed.</p>
<p>8.)<br />
SQL&gt;  exec rc(&#8216;C:WINDOWSsystem32cmd.EXE /c dir C:SCOTT&#8217;)<br />
BEGIN rc(&#8216;C:WINDOWSsystem32cmd.EXE /c dir C:SCOTT&#8217;); END;</p>
<p>*<br />
ERROR at line 1:<br />
ORA-06501: PL/SQL: program error<br />
ORA-06512: at &#8220;SCOTT.RC&#8221;, line 10<br />
ORA-06512: at line 1</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Karnail J Singh</title>
		<link>http://technology.amis.nl/2005/02/11/stored-java-to-run-an-os-command-copy-a-file-and-get-a-directory-listing/#comment-1704</link>
		<dc:creator>Karnail J Singh</dc:creator>
		<pubDate>Sat, 25 Feb 2006 04:44:16 +0000</pubDate>
		<guid isPermaLink="false">/?p=394#comment-1704</guid>
		<description><![CDATA[I tried running the above procedure to execute the cmd but it just hangs the session
and eventually I have to kill it.

I want to use the above procedure to run the oracle reports (rwcli60.exe) to print
reports from a procedure.

Please advice me if you had encounted similar problem and if so is there a solution.

Thanks
Karnail]]></description>
		<content:encoded><![CDATA[<p>I tried running the above procedure to execute the cmd but it just hangs the session<br />
and eventually I have to kill it.</p>
<p>I want to use the above procedure to run the oracle reports (rwcli60.exe) to print<br />
reports from a procedure.</p>
<p>Please advice me if you had encounted similar problem and if so is there a solution.</p>
<p>Thanks<br />
Karnail</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Arun</title>
		<link>http://technology.amis.nl/2005/02/11/stored-java-to-run-an-os-command-copy-a-file-and-get-a-directory-listing/#comment-1703</link>
		<dc:creator>Arun</dc:creator>
		<pubDate>Mon, 27 Jun 2005 19:52:51 +0000</pubDate>
		<guid isPermaLink="false">/?p=394#comment-1703</guid>
		<description><![CDATA[Can i use zip and unzip commands in this ?
my project requirements, want me to unzip a file from folder and then process it.
Can i use runcmd for that?]]></description>
		<content:encoded><![CDATA[<p>Can i use zip and unzip commands in this ?<br />
my project requirements, want me to unzip a file from folder and then process it.<br />
Can i use runcmd for that?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vasso</title>
		<link>http://technology.amis.nl/2005/02/11/stored-java-to-run-an-os-command-copy-a-file-and-get-a-directory-listing/#comment-1702</link>
		<dc:creator>Vasso</dc:creator>
		<pubDate>Thu, 02 Jun 2005 10:36:32 +0000</pubDate>
		<guid isPermaLink="false">/?p=394#comment-1702</guid>
		<description><![CDATA[Hello! Congratulations. Your solution has been very helpful because utl_file.fcopy couldn&#039;t copy pdf files correctly (in 9i)
Thank you!]]></description>
		<content:encoded><![CDATA[<p>Hello! Congratulations. Your solution has been very helpful because utl_file.fcopy couldn&#8217;t copy pdf files correctly (in 9i)<br />
Thank you!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: harm</title>
		<link>http://technology.amis.nl/2005/02/11/stored-java-to-run-an-os-command-copy-a-file-and-get-a-directory-listing/#comment-1701</link>
		<dc:creator>harm</dc:creator>
		<pubDate>Sat, 12 Feb 2005 10:33:32 +0000</pubDate>
		<guid isPermaLink="false">/?p=394#comment-1701</guid>
		<description><![CDATA[Hi Gregory,

UTL_FILE is only capable of reading on and writing to the file system of the database server. How about your functions? I see that you perform I/O on your local C: drive. Can they I/O from any client PC or do you happen to run a local database?
The 10g version of UTL_FILE has a copy (utl_file.fcopy) procedure that can do a whole or partial copy of a file, but it is restricted only to the server file system.

*********************************************************************************************************

Hello Harm,

Thanks for your comment.
These (my) functionalities are also restricted to the database server filesystem.
I know about the Utl_File.Fcopy (since Oracle 9.2.0), but I needed it in 8.1.7.

Gregory]]></description>
		<content:encoded><![CDATA[<p>Hi Gregory,</p>
<p>UTL_FILE is only capable of reading on and writing to the file system of the database server. How about your functions? I see that you perform I/O on your local C: drive. Can they I/O from any client PC or do you happen to run a local database?<br />
The 10g version of UTL_FILE has a copy (utl_file.fcopy) procedure that can do a whole or partial copy of a file, but it is restricted only to the server file system.</p>
<p>*********************************************************************************************************</p>
<p>Hello Harm,</p>
<p>Thanks for your comment.<br />
These (my) functionalities are also restricted to the database server filesystem.<br />
I know about the Utl_File.Fcopy (since Oracle 9.2.0), but I needed it in 8.1.7.</p>
<p>Gregory</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lucas</title>
		<link>http://technology.amis.nl/2005/02/11/stored-java-to-run-an-os-command-copy-a-file-and-get-a-directory-listing/#comment-1700</link>
		<dc:creator>Lucas</dc:creator>
		<pubDate>Fri, 11 Feb 2005 14:27:41 +0000</pubDate>
		<guid isPermaLink="false">/?p=394#comment-1700</guid>
		<description><![CDATA[Can you make the sources available as zip-file or perhaps even a JDev project, please?]]></description>
		<content:encoded><![CDATA[<p>Can you make the sources available as zip-file or perhaps even a JDev project, please?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
