MCPcopy Create free account
hub / github.com/boostorg/build / invoke_cmd

Function invoke_cmd

v2/engine/execnt.c:429–501  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

427 */
428
429static void invoke_cmd( char const * const command, int const slot )
430{
431 SECURITY_ATTRIBUTES sa = { sizeof( SECURITY_ATTRIBUTES ), 0, 0 };
432 SECURITY_DESCRIPTOR sd;
433 STARTUPINFO si = { sizeof( STARTUPINFO ), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
434 0, 0, 0, 0, 0, 0 };
435
436 /* Init the security data. */
437 InitializeSecurityDescriptor( &sd, SECURITY_DESCRIPTOR_REVISION );
438 SetSecurityDescriptorDacl( &sd, TRUE, NULL, FALSE );
439 sa.lpSecurityDescriptor = &sd;
440 sa.bInheritHandle = TRUE;
441
442 /* Create pipes for communicating with the child process. */
443 if ( !CreatePipe( &cmdtab[ slot ].pipe_out[ EXECCMD_PIPE_READ ],
444 &cmdtab[ slot ].pipe_out[ EXECCMD_PIPE_WRITE ], &sa, 0 ) )
445 {
446 reportWindowsError( "CreatePipe" );
447 exit( EXITBAD );
448 }
449 if ( globs.pipe_action && !CreatePipe( &cmdtab[ slot ].pipe_err[
450 EXECCMD_PIPE_READ ], &cmdtab[ slot ].pipe_err[ EXECCMD_PIPE_WRITE ],
451 &sa, 0 ) )
452 {
453 reportWindowsError( "CreatePipe" );
454 exit( EXITBAD );
455 }
456
457 /* Set handle inheritance off for the pipe ends the parent reads from. */
458 SetHandleInformation( cmdtab[ slot ].pipe_out[ EXECCMD_PIPE_READ ],
459 HANDLE_FLAG_INHERIT, 0 );
460 if ( globs.pipe_action )
461 SetHandleInformation( cmdtab[ slot ].pipe_err[ EXECCMD_PIPE_READ ],
462 HANDLE_FLAG_INHERIT, 0 );
463
464 /* Hide the child window, if any. */
465 si.dwFlags |= STARTF_USESHOWWINDOW;
466 si.wShowWindow = SW_HIDE;
467
468 /* Redirect the child's output streams to our pipes. */
469 si.dwFlags |= STARTF_USESTDHANDLES;
470 si.hStdOutput = cmdtab[ slot ].pipe_out[ EXECCMD_PIPE_WRITE ];
471 si.hStdError = globs.pipe_action
472 ? cmdtab[ slot ].pipe_err[ EXECCMD_PIPE_WRITE ]
473 : cmdtab[ slot ].pipe_out[ EXECCMD_PIPE_WRITE ];
474
475 /* Let the child inherit stdin, as some commands assume it is available. */
476 si.hStdInput = GetStdHandle( STD_INPUT_HANDLE );
477
478 /* Create output buffers. */
479 string_new( cmdtab[ slot ].buffer_out );
480 string_new( cmdtab[ slot ].buffer_err );
481
482 if ( DEBUG_EXECCMD )
483 printf( "Command string for CreateProcessA(): '%s'\n", command );
484
485 /* Run the command by creating a sub-process for it. */
486 if ( !CreateProcessA(

Callers 1

exec_cmdFunction · 0.85

Calls 2

reportWindowsErrorFunction · 0.85
string_newFunction · 0.85

Tested by

no test coverage detected