Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: problem with java function which runs a Unix command

Re: problem with java function which runs a Unix command

From: Gerard H. Pille <ghp_at_skynet.be>
Date: Tue, 10 Feb 2004 00:26:09 +0100
Message-ID: <402815a3$0$768$ba620e4c@news.skynet.be>


John Leslie wrote:
> I have a problem with a java function that I use to run unix commands.
>
> It works OK for most commands(for example touch works fine), but I am
> having problem with the echo command.
>
> I am wondering whether the problem is the redirection sign >
>
>
>
> Plaform is Oracle 9.2 on Solaris but same problem occurs on AIX
>
> Below is the code and the sql script I use to test.
>
> Any thoughts?
>
> ------------------------------------------------------------------------------------------------
>
> CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "function_os_command"
> AS
>
> import java.io.*;
>
> import java.util.*;
>
> public class function_os_command
>
> {
>
> public static int Run(String Command)
>
> {
>
> int rc = 0;
>
> try
>
> {
>
> Runtime rt = Runtime.getRuntime();
>
> Process p = rt.exec(Command);
>
> try {
>
> rc = p.waitFor();
>
> } catch (InterruptedException intexc) { rc = 2; }
>
> } catch (Throwable t) { rc = 3; }
>
> return(rc);
>
> }
>
> }
>
> /
>
> CREATE or REPLACE FUNCTION function_run_os_command(Command IN STRING)
>
> RETURN NUMBER IS
>
> LANGUAGE JAVA
>
> NAME 'function_os_command.Run(java.lang.String) return integer';
>
> /
>
>
>
>
>
>
>
> sql script to test it
>
> /* example call to unix function */
>
> set serveroutput on
>
> VARIABLE retcode NUMBER;
>
> begin
>
> --:retcode := function_run_os_command('/usr/bin/echo hello >
> /tmp/testecho');
>
> :retcode := function_run_os_command('/usr/bin/touch /tmp/testecho');
>
>
>
> dbms_output.put_line('retcode ' || :retcode);
>
> end;
>
> .
>
> /
>
> exit

You may stand a chance by calling a shell with the arguments   "-c"
  and
  "echo hello > /tmp/testecho".

But java is no good for interaction with an OS.

Geert Received on Mon Feb 09 2004 - 17:26:09 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US