summaryrefslogtreecommitdiff
path: root/client/mysqltest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'client/mysqltest.cc')
-rw-r--r--client/mysqltest.cc62
1 files changed, 56 insertions, 6 deletions
diff --git a/client/mysqltest.cc b/client/mysqltest.cc
index 0f553cab3f3..cb5a20c4c0f 100644
--- a/client/mysqltest.cc
+++ b/client/mysqltest.cc
@@ -3294,6 +3294,47 @@ static int replace(DYNAMIC_STRING *ds_str,
return 0;
}
+#ifdef _WIN32
+/**
+ Check if background execution of command was requested.
+ Like in Unix shell, we assume background execution of the last
+ character in command is a ampersand (we do not tokenize though)
+*/
+static bool is_background_command(const DYNAMIC_STRING *ds)
+{
+ for (size_t i= ds->length - 1; i > 1; i--)
+ {
+ char c= ds->str[i];
+ if (!isspace(c))
+ return (c == '&');
+ }
+ return false;
+}
+
+/**
+ Execute OS command in background. We assume that the last character
+ is ampersand, i.e is_background_command() returned
+*/
+#include <string>
+static int execute_in_background(char *cmd)
+{
+ STARTUPINFO s{};
+ PROCESS_INFORMATION pi{};
+ char *end= strrchr(cmd, '&');
+ DBUG_ASSERT(end);
+ *end =0;
+ std::string scmd("cmd /c ");
+ scmd.append(cmd);
+ BOOL ok=
+ CreateProcess(0, (char *)scmd.c_str(), 0, 0, 0, CREATE_NO_WINDOW, 0, 0, &s, &pi);
+ *end= '&';
+ if (!ok)
+ return (int) GetLastError();
+ CloseHandle(pi.hProcess);
+ CloseHandle(pi.hThread);
+ return 0;
+}
+#endif
/*
Execute given command.
@@ -3368,6 +3409,14 @@ void do_exec(struct st_command *command)
DBUG_PRINT("info", ("Executing '%s' as '%s'",
command->first_argument, ds_cmd.str));
+#ifdef _WIN32
+ if (is_background_command(&ds_cmd))
+ {
+ error= execute_in_background(ds_cmd.str);
+ goto end;
+ }
+#endif
+
if (!(res_file= my_popen(ds_cmd.str, "r")))
{
dynstr_free(&ds_cmd);
@@ -3394,7 +3443,9 @@ void do_exec(struct st_command *command)
dynstr_append_sorted(&ds_res, &ds_sorted, 0);
dynstr_free(&ds_sorted);
}
-
+#ifdef _WIN32
+end:
+#endif
if (error)
{
uint status= WEXITSTATUS(error);
@@ -3689,8 +3740,7 @@ void do_remove_file(struct st_command *command)
void do_remove_files_wildcard(struct st_command *command)
{
int error= 0, sys_errno= 0;
- uint i;
- size_t directory_length;
+ size_t i, directory_length;
MY_DIR *dir_info;
FILEINFO *file;
char dir_separator[2];
@@ -3729,7 +3779,7 @@ void do_remove_files_wildcard(struct st_command *command)
/* Set default wild chars for wild_compare, is changed in embedded mode */
set_wild_chars(1);
- for (i= 0; i < (uint) dir_info->number_of_files; i++)
+ for (i= 0; i < dir_info->number_of_files; i++)
{
file= dir_info->dir_entry + i;
/* Remove only regular files, i.e. no directories etc. */
@@ -4003,7 +4053,7 @@ void do_rmdir(struct st_command *command)
static int get_list_files(DYNAMIC_STRING *ds, const DYNAMIC_STRING *ds_dirname,
const DYNAMIC_STRING *ds_wild)
{
- uint i;
+ size_t i;
MY_DIR *dir_info;
FILEINFO *file;
DBUG_ENTER("get_list_files");
@@ -4012,7 +4062,7 @@ static int get_list_files(DYNAMIC_STRING *ds, const DYNAMIC_STRING *ds_dirname,
if (!(dir_info= my_dir(ds_dirname->str, MYF(MY_WANT_SORT))))
DBUG_RETURN(1);
set_wild_chars(1);
- for (i= 0; i < (uint) dir_info->number_of_files; i++)
+ for (i= 0; i < dir_info->number_of_files; i++)
{
file= dir_info->dir_entry + i;
if (ds_wild && ds_wild->length &&