Home » SQL & PL/SQL » SQL & PL/SQL » Unix command through external procedure in C running successfully but showing no output.
Unix command through external procedure in C running successfully but showing no output. [message #238233] Thu, 17 May 2007 02:57 Go to next message
truth_bajaj
Messages: 5
Registered: May 2007
Junior Member
Hi,

I am using Oracle 9i and Unix on my system and trying to execute a UNIX shell command through external procedure in C.

I created a shared lib (libextproc.so) for the following function.

int sysrun(char *command)
{
return system(command);
}

This function runs fine when caled through a driver function in C, meaning that the shared lib is fine.


In PL/SQL, I have used the following method to invoke a UNIX command:-

create or replace library shell_lib as '/home/ECETRAonsite/oracle/OraHome1/lib/libextproc.so';
/


create or replace function sysrun (syscomm in varchar2)
return binary_integer
as language C
name "sysrun"
library shell_lib
parameters(syscomm string);
/

Now when I call this PL/SQL function to invoke the command, it is run succesfully but displays no output from 'ls'.

SQL>
1 declare
2 rc number;
3 begin
4 rc := sysrun('/bin/ls -l');
5 dbms_output.put_line('Return Code='||rc);
6* end;
SQL> /
Return Code=0

PL/SQL procedure successfully completed.

I have verified that the path for 'ls' is correct.

I have also tried o use another command like '/bin/touch /home/ECETRAonsite/oracle/OraHome1/test/sach' but to no avail.

Following are my configuration files.

listener.ora
-------------
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
)
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST =172.21.161.69 )(PORT = 1521)(KEY = ECTPRF))
)

)
)

SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = extproc2)
(ORACLE_HOME = /home/ECETRAonsite/oracle/OraHome1)
(PROGRAM = extproc)
(ENVS = "EXTPROC_DLLS=ANY")

)
(SID_DESC =
(SID_NAME = ECTPRF)
(ORACLE_HOME = /home/ECETRAonsite/oracle/OraHome1)
(ENVS = "EXTPROC_DLLS=ANY")
)
)


tnsnames.ora
-------------
EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
)
(CONNECT_DATA =
(SID = extproc2)
)
)


Please suggest what is lacking for this to work properly.

Thanks,

[Updated on: Thu, 17 May 2007 03:09]

Report message to a moderator

Re: Unix command through external procedure in C running successfully but showing no output. [message #238240 is a reply to message #238233] Thu, 17 May 2007 03:08 Go to previous messageGo to next message
Michel Cadot
Messages: 64139
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
But your function returns the return code, so you get what you return.

Search on AskTom, there are many procedures on how to do it.

Regards
Michel
Re: Unix command through external procedure in C running successfully but showing no output. [message #238242 is a reply to message #238240] Thu, 17 May 2007 03:11 Go to previous messageGo to next message
truth_bajaj
Messages: 5
Registered: May 2007
Junior Member
I have also tried o use another command like '/bin/touch /home/ECETRAonsite/oracle/OraHome1/test/sach' but to no avail.

Also, how do i obtain the output of ls in SQLPLUS?
Re: Unix command through external procedure in C running successfully but showing no output. [message #238247 is a reply to message #238242] Thu, 17 May 2007 03:22 Go to previous messageGo to next message
Michel Cadot
Messages: 64139
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Once again, this is the expected behaviour with what you posted.
Once again, search on AskTom there is your answer and will not search for you and post what you can find by yourself.

Regards
Michel
Re: Unix command through external procedure in C running successfully but showing no output. [message #238284 is a reply to message #238247] Thu, 17 May 2007 05:37 Go to previous messageGo to next message
truth_bajaj
Messages: 5
Registered: May 2007
Junior Member
Michel,

You are right that the result at PL/SQL side is as expected but the touch command should have created a file named /home/ECETRAonsite/oracle/OraHome1/test/sach

But this is not getting created.

Any views on that?
Re: Unix command through external procedure in C running successfully but showing no output. [message #238294 is a reply to message #238284] Thu, 17 May 2007 06:15 Go to previous message
Michel Cadot
Messages: 64139
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
And what about the link I posted?

Regards
Michel
Previous Topic: how cani pass reference varibles in a procedure
Next Topic: New Issue in ORDER BY 10g
Goto Forum:
  


Current Time: Thu Dec 08 20:14:22 CST 2016

Total time taken to generate the page: 0.04702 seconds