diff options
Diffstat (limited to 'client')
-rw-r--r-- | client/mysqltest.c | 43 |
1 files changed, 34 insertions, 9 deletions
diff --git a/client/mysqltest.c b/client/mysqltest.c index 5836a109b6e..2486aab4c65 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -455,6 +455,7 @@ static void do_eval(DYNAMIC_STRING *query_eval, const char *query, static void str_to_file(const char *fname, char *str, int size); #ifdef __WIN__ +static void free_tmp_sh_file(); static void free_win_path_patterns(); #endif @@ -604,6 +605,7 @@ static void free_used_memory() mysql_server_end(); free_re(); #ifdef __WIN__ + free_tmp_sh_file(); free_win_path_patterns(); #endif DBUG_VOID_RETURN; @@ -1046,6 +1048,35 @@ int do_source(struct st_query *query) return open_file(name); } +//#ifdef __WIN__ +/* Variables used for temuprary sh files used for emulating Unix on Windows */ +char tmp_sh_name[64], tmp_sh_cmd[70]; + +static void init_tmp_sh_file() +{ + /* Format a name for the tmp sh file that is unique for this process */ + my_snprintf(tmp_sh_name, sizeof(tmp_sh_name), "tmp_%d.sh", getpid()); + /* Format the command to execute in order to run the script */ + my_snprintf(tmp_sh_cmd, sizeof(tmp_sh_cmd), "sh %s", tmp_sh_name); +} + +static void free_tmp_sh_file() +{ + my_delete(tmp_sh_name, MYF(0)); +} + + +FILE* my_popen(DYNAMIC_STRING* ds_cmd, const char* mode) +{ +#ifdef __WIN__ + /* Dump the command into a sh script file and execute with popen */ + str_to_file(tmp_sh_name, ds_cmd->str, ds_cmd->length); + return popen(tmp_sh_cmd, mode); +#else + return popen(ds_cmd->str, mode); +#endif +} + /* Execute given command. @@ -1092,7 +1123,7 @@ static void do_exec(struct st_query *query) DBUG_PRINT("info", ("Executing '%s' as '%s'", query->first_argument, cmd)); - if (!(res_file= popen(cmd, "r")) && query->abort_on_error) + if (!(res_file= my_popen(&ds_cmd, "r")) && query->abort_on_error) die("popen(\"%s\", \"r\") failed", query->first_argument); while (fgets(buf, sizeof(buf), res_file)) @@ -1365,15 +1396,9 @@ int do_modify_var(struct st_query *query, const char *name, int my_system(DYNAMIC_STRING* ds_cmd) { #ifdef __WIN__ - /* Dump the command into a sh script file and execute with "sh" */ - int err; - char tmp_sh_name[64], tmp_sh_cmd[70]; - my_snprintf(tmp_sh_name, sizeof(tmp_sh_name), "tmp_%d.sh", getpid()); - my_snprintf(tmp_sh_cmd, sizeof(tmp_sh_cmd), "sh %s", tmp_sh_name); + /* Dump the command into a sh script file and execute with system */ str_to_file(tmp_sh_name, ds_cmd->str, ds_cmd->length); - err= system(tmp_sh_cmd); - my_delete(tmp_sh_name, MYF(0)); - return err; + return system(tmp_sh_cmd); #else return system(ds_cmd->str); #endif |