Skip navigation links

MySQL Forums :: UDF :: system() and fork()/exec() within a UDF (in Unix) ?


Advanced Search

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 'lib_mysqludf_sys.so';
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
/home/roland/testudf
roland@roland-laptop:~/testudf$ ls
test.txt

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 {
strcpy(
message
, "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
http://rpbouman.blogspot.com/

Options: ReplyQuote


Subject Views Written By Posted
system() and fork()/exec() within a UDF (in Unix) ? 9332 Rather Notsay 06/25/2008 12:49PM
Re: system() and fork()/exec() within a UDF (in Unix) ? 3844 Roland Bouman 06/25/2008 01:18PM
Re: system() and fork()/exec() within a UDF (in Unix) ? 5028 Roland Bouman 06/25/2008 01:35PM
Re: system() and fork()/exec() within a UDF (in Unix) ? 3943 Rather Notsay 06/25/2008 04:20PM
Re: system() and fork()/exec() within a UDF (in Unix) ? 3889 Roland Bouman 06/25/2008 04:43PM
Re: system() and fork()/exec() within a UDF (in Unix) ? 4101 Rather Notsay 06/26/2008 09:07AM
Re: system() and fork()/exec() within a UDF (in Unix) ? 2994 Roland Bouman 06/26/2008 12:09PM
Re: system() and fork()/exec() within a UDF (in Unix) ? 3322 Rather Notsay 06/26/2008 01:47PM
Re: system() and fork()/exec() within a UDF (in Unix) ? 6033 Roland Bouman 07/18/2008 05:19AM
Re: system() and fork()/exec() within a UDF (in Unix) ? 3826 Pablo Casado 12/15/2008 10:55AM


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.