Link to home
Start Free TrialLog in
Avatar of jujin
jujin

asked on

how can I run command line or shell script in Oracle

Please help me to create one text file to save all file names in directory
To put all filenames.dat into one file called datNames.txt I wrote a procedure as
create or replace
procedure host(cmd in varchar2 )
as
status number;
begin
dbms_pipe.pack_message( cmd );
status := dbms_pipe.send_message( 'HOST_PIPE' );
if ( status <> 0 ) then raise_application_error( -20001, 'Pipe error' );
end if;
end;
---------------------
I run the procedure in PL/SQL as
begin
  host('dir/b c:\dataloader\upload\*.dat > c:\dataloader\upload\datNames.txt');
end;
There is not error but it can not create c:\dataloader\upload\datNames.txt' eventhough I have granted write permission on the directory. But when I run it in MS DOs, It run OK.
Another question, I use 'dir/b c:\dataloader\upload\*.dat > c:\dataloader\upload\datNames.txt'  to run on window but if I want run  the procedure on Linux so Which shell script will be used to replace the MS DOS command line?
Avatar of Sujith
Sujith
Flag of United Kingdom of Great Britain and Northern Ireland image

>> There is not error but it can not create
Do you have a supporting pro*C code that reads the pipe and execute the command?

>> Which shell script will be used to replace the MS DOS command line?
You should pass a different command to the procedure in Linux.
Avatar of jujin
jujin

ASKER

hi sujith80
Not yet, I don't know how to support pro*C code to reads the pipe and execute the command. How can I do that?
You should have a host language program(Pro*C or Java or ...) that reads the pipe and executes your command. DBMS_PIPE does "NOT" execute the commands.

See this link for a detailed example:
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_pipe.htm#CHDDFCFC
ASKER CERTIFIED SOLUTION
Avatar of Mark Geerlings
Mark Geerlings
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Using dbms pipes also perfectly works to execute operating system commands. But DBMS_PIPE does NOT EXECUTE your commands. You have to write another program to read the pipe and execute the commands. This second program can be written in ANY host language that can read the pipe using DBMS_PIPE.