| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include <process.h> | 5 #include <process.h> |
| 6 | 6 |
| 7 #include "bin/builtin.h" | 7 #include "bin/builtin.h" |
| 8 #include "bin/process.h" | 8 #include "bin/process.h" |
| 9 #include "bin/eventhandler.h" | 9 #include "bin/eventhandler.h" |
| 10 #include "bin/thread.h" | 10 #include "bin/thread.h" |
| (...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 startup_info.dwFlags |= STARTF_USESTDHANDLES; | 553 startup_info.dwFlags |= STARTF_USESTDHANDLES; |
| 554 | 554 |
| 555 PROCESS_INFORMATION process_info; | 555 PROCESS_INFORMATION process_info; |
| 556 ZeroMemory(&process_info, sizeof(process_info)); | 556 ZeroMemory(&process_info, sizeof(process_info)); |
| 557 | 557 |
| 558 // Compute command-line length. | 558 // Compute command-line length. |
| 559 int command_line_length = strlen(path); | 559 int command_line_length = strlen(path); |
| 560 for (int i = 0; i < arguments_length; i++) { | 560 for (int i = 0; i < arguments_length; i++) { |
| 561 command_line_length += strlen(arguments[i]); | 561 command_line_length += strlen(arguments[i]); |
| 562 } | 562 } |
| 563 // Account for two occurrences of '"' around the command, one | 563 // Account for two occurrences of '"' around the command, one space |
| 564 // space per argument and a terminating '\0'. | 564 // and two occurrences of '"' per argument and a terminating '\0'. |
| 565 command_line_length += 2 + arguments_length + 1; | 565 command_line_length += 2 + (3 * arguments_length) + 1; |
| 566 static const int kMaxCommandLineLength = 32768; | 566 static const int kMaxCommandLineLength = 32768; |
| 567 if (command_line_length > kMaxCommandLineLength) { | 567 if (command_line_length > kMaxCommandLineLength) { |
| 568 int error_code = SetOsErrorMessage(os_error_message, os_error_message_len); | 568 int error_code = SetOsErrorMessage(os_error_message, os_error_message_len); |
| 569 CloseProcessPipes( | 569 CloseProcessPipes( |
| 570 stdin_handles, stdout_handles, stderr_handles, exit_handles); | 570 stdin_handles, stdout_handles, stderr_handles, exit_handles); |
| 571 return error_code; | 571 return error_code; |
| 572 } | 572 } |
| 573 | 573 |
| 574 // Put together command-line string. | 574 // Put together command-line string. |
| 575 char* command_line = new char[command_line_length]; | 575 char* command_line = new char[command_line_length]; |
| 576 int len = 0; | 576 int len = 0; |
| 577 int remaining = command_line_length; | 577 int remaining = command_line_length; |
| 578 int written = snprintf(command_line + len, remaining, "\"%s\"", path); | 578 int written = snprintf(command_line + len, remaining, "\"%s\"", path); |
| 579 len += written; | 579 len += written; |
| 580 remaining -= written; | 580 remaining -= written; |
| 581 ASSERT(remaining >= 0); | 581 ASSERT(remaining >= 0); |
| 582 for (int i = 0; i < arguments_length; i++) { | 582 for (int i = 0; i < arguments_length; i++) { |
| 583 written = snprintf(command_line + len, remaining, " %s", arguments[i]); | 583 written = snprintf(command_line + len, remaining, " \"%s\"", arguments[i]); |
| 584 len += written; | 584 len += written; |
| 585 remaining -= written; | 585 remaining -= written; |
| 586 ASSERT(remaining >= 0); | 586 ASSERT(remaining >= 0); |
| 587 } | 587 } |
| 588 | 588 |
| 589 // Create process. | 589 // Create process. |
| 590 BOOL result = CreateProcess(NULL, // ApplicationName | 590 BOOL result = CreateProcess(NULL, // ApplicationName |
| 591 command_line, | 591 command_line, |
| 592 NULL, // ProcessAttributes | 592 NULL, // ProcessAttributes |
| 593 NULL, // ThreadAttributes | 593 NULL, // ThreadAttributes |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 if (!result) { | 643 if (!result) { |
| 644 return false; | 644 return false; |
| 645 } | 645 } |
| 646 return true; | 646 return true; |
| 647 } | 647 } |
| 648 | 648 |
| 649 | 649 |
| 650 void Process::TerminateExitCodeHandler() { | 650 void Process::TerminateExitCodeHandler() { |
| 651 ExitCodeHandler::TerminateExitCodeThread(); | 651 ExitCodeHandler::TerminateExitCodeThread(); |
| 652 } | 652 } |
| OLD | NEW |