| From: | Joe Conway <mail(at)joeconway(dot)com> | 
|---|---|
| To: | Nicholas Walker <nick(at)walkerdatanet(dot)com> | 
| Cc: | pgsql-general(at)postgresql(dot)org | 
| Subject: | Re: Executing Shell Command | 
| Date: | 2003-11-29 02:39:58 | 
| Message-ID: | 3FC806FE.5040800@joeconway.com | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-general | 
Nicholas Walker wrote:
> I have been trying to execute a shell command from within postgresql
You ought to be using Version 1 calling conventions -- see:
http://www.postgresql.org/docs/current/static/xfunc-c.html#AEN29226
The following works fine for me on RH9:
#define GET_STR(textp) \
   DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(textp)))
extern Datum shell_exec(PG_FUNCTION_ARGS);
PG_FUNCTION_INFO_V1(shell_exec);
Datum
shell_exec(PG_FUNCTION_ARGS)
{
     char   *cmd = GET_STR(PG_GETARG_TEXT_P(0));
     int32   result;
     result = system(cmd);
     PG_RETURN_INT32(result);
}
CREATE OR REPLACE FUNCTION xp_shellexec(text)
RETURNS int
AS '$libdir/shell_exec','shell_exec'
LANGUAGE 'C' VOLATILE STRICT;
SELECT xp_shellexec('mkdir /tmp/testing123');
[root(at)dev tmp]# ls -ld /tmp/test*
drwx------    2 postgres postgres     4096 Nov 28 19:31 /tmp/testing123
HTH,
Joe
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Chris Travers | 2003-11-29 02:41:17 | Re: PostgreSQL Advocacy, Thoughts and Comments | 
| Previous Message | Randolf Richardson | 2003-11-29 01:12:43 | Re: PostgreSQL, MySQL, etc., was Re: PostgreSQL is much faster than MySQL, only when... |