@@ -3251,6 +3251,47 @@ static int replace(DYNAMIC_STRING *ds_str,
3251
3251
return 0 ;
3252
3252
}
3253
3253
3254
+ #ifdef _WIN32
3255
+ /* *
3256
+ Check if background execution of command was requested.
3257
+ Like in Unix shell, we assume background execution of the last
3258
+ character in command is a ampersand (we do not tokenize though)
3259
+ */
3260
+ static bool is_background_command (const DYNAMIC_STRING *ds)
3261
+ {
3262
+ for (size_t i= ds->length - 1 ; i > 1 ; i--)
3263
+ {
3264
+ char c= ds->str [i];
3265
+ if (!isspace (c))
3266
+ return (c == ' &' );
3267
+ }
3268
+ return false ;
3269
+ }
3270
+
3271
+ /* *
3272
+ Execute OS command in background. We assume that the last character
3273
+ is ampersand, i.e is_background_command() returned
3274
+ */
3275
+ #include < string>
3276
+ static int execute_in_background (char *cmd)
3277
+ {
3278
+ STARTUPINFO s{};
3279
+ PROCESS_INFORMATION pi{};
3280
+ char *end= strrchr (cmd, ' &' );
3281
+ DBUG_ASSERT (end);
3282
+ *end =0 ;
3283
+ std::string scmd (" cmd /c " );
3284
+ scmd.append (cmd);
3285
+ BOOL ok=
3286
+ CreateProcess (0 , (char *)scmd.c_str (), 0 , 0 , 0 , CREATE_NO_WINDOW, 0 , 0 , &s, &pi);
3287
+ *end= ' &' ;
3288
+ if (!ok)
3289
+ return (int ) GetLastError ();
3290
+ CloseHandle (pi.hProcess );
3291
+ CloseHandle (pi.hThread );
3292
+ return 0 ;
3293
+ }
3294
+ #endif
3254
3295
3255
3296
/*
3256
3297
Execute given command.
@@ -3325,6 +3366,14 @@ void do_exec(struct st_command *command)
3325
3366
DBUG_PRINT (" info" , (" Executing '%s' as '%s'" ,
3326
3367
command->first_argument , ds_cmd.str ));
3327
3368
3369
+ #ifdef _WIN32
3370
+ if (is_background_command (&ds_cmd))
3371
+ {
3372
+ error= execute_in_background (ds_cmd.str );
3373
+ goto end;
3374
+ }
3375
+ #endif
3376
+
3328
3377
if (!(res_file= my_popen (ds_cmd.str , " r" )))
3329
3378
{
3330
3379
dynstr_free (&ds_cmd);
@@ -3351,7 +3400,9 @@ void do_exec(struct st_command *command)
3351
3400
dynstr_append_sorted (&ds_res, &ds_sorted, 0 );
3352
3401
dynstr_free (&ds_sorted);
3353
3402
}
3354
-
3403
+ #ifdef _WIN32
3404
+ end:
3405
+ #endif
3355
3406
if (error)
3356
3407
{
3357
3408
uint status= WEXITSTATUS (error);
0 commit comments