MySQL Forums
Forum List  »  UDF

Re: system() and fork()/exec() within a UDF (in Unix) ?
Posted by: Roland Bouman
Date: June 25, 2008 01:35PM

Well, I just freshly compiled my udf, and installed it in MySQL 5.1.23:

mysql> create function sys_exec returns int soname '';
Query OK, 0 rows affected (0.74 sec)

I then set up test directory with a little file in it:

roland@roland-laptop:~/testudf$ pwd
roland@roland-laptop:~/testudf$ ls

And then I ran this SQL:

mysql> set @status := sys_exec('cp /home/roland/testudf/test.txt /home/roland/testudf/copy_of_text.txt');
Query OK, 0 rows affected (0.01 sec)

mysql> select @status;
| @status |
| 0 |
1 row in set (0.00 sec)

After that I checked the directory again:

roland@roland-laptop:~/testudf$ ls
copy_of_text.txt test.txt

And this indicates the file was copied, in accordance with the command passed to the system function.

So, lib_mysqludf_sys is working as I expect and intended.

Can you indicate how you determined that the program you want to call does not start? Are you sure the command you extract from the parameters is a valid command line? You can print it to the MySQL error log using:

fprintf(stderr, '%s', command_string);

To be sure, this is my UDF code:

my_bool sys_exec_init(
UDF_INIT *initid
, UDF_ARGS *args
, char *message
unsigned int i=0;
if(args->arg_count == 1
&& args->arg_type==STRING_RESULT){
return 0;
} else {
, "Expected exactly one string type parameter"
return 1;
void sys_exec_deinit(
UDF_INIT *initid
my_ulonglong sys_exec(
UDF_INIT *initid
, UDF_ARGS *args
, char *is_null
, char *error
return system(args->args[0]);

kind regards,

Roland Bouman

Options: ReplyQuote

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.