PL/SQL and External Procedures
636353Apr 27 2008 — edited Apr 29 2008Hello,
I have written a simple C program that I have defined as an Oracle external procedure.
Here is my anonymous PL/SQL block I have executing:
set serveroutput on size 100000;
declare
begin
dbms_output.put_line(sysrun('hostname'));
end;
/
The external procedure sysrun is a small C function:
#include <stdio.h>
void sysrun(char * command)
{
FILE * input_stream;
char os[1000];
int lastchar;
input_stream = popen(command, "r");
lastchar = fread(os, 1, 1000, input_stream);
os[lastchar] = '\0';
printf("%s",os);
pclose(input_stream);
}
The intent for this setup is to simply run OS commands from within my PL/SQL block and send the output (not the return code) to standard out. When I execute the PL/SQL block it succeeds, but instead of getting the desired output I get an integer.
SQL> list
1 declare
2 begin
3 dbms_output.put_line(sysrun('hostname'));
4* end;
SQL> /
446204
PL/SQL procedure successfully completed.
What I want is the Unix machines "hostname" output. I am sure that I am just overlooking something very easy. But, I can't quite figure it out.
Any help is appreciated.
Thanks