[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

how can I run command line or shell script in Oracle

Posted on 2007-12-04
5
Medium Priority
?
3,941 Views
Last Modified: 2008-02-01
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?
0
Comment
Question by:jujin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 27

Expert Comment

by:sujith80
ID: 20401593
>> 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.
0
 

Author Comment

by:jujin
ID: 20401828
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?
0
 
LVL 27

Expert Comment

by:sujith80
ID: 20401961
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
0
 
LVL 35

Accepted Solution

by:
Mark Geerlings earned 250 total points
ID: 20402562
To put it simply: in SQL*Plus you *CAN* execute "host" commands directly, but in PL\SQL you *CANNOT* do that!  PL\SQL does not directly support "host" commands.  What you can do in PL\SQL though is call Java procedures, and Java can do "host" commands.  So, what you need to do is find (or write) a Java procedure to do the operating system tasks you want, then from PL\SQL you call the Java procedure.
0
 
LVL 27

Expert Comment

by:sujith80
ID: 20417044
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.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question