Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Side by Side Diff: runtime/bin/process.cc

Issue 21816002: Add Process.runSync for running processe synchronously. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixed another Windows issue Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 "bin/dartutils.h" 5 #include "bin/dartutils.h"
6 #include "bin/io_buffer.h" 6 #include "bin/io_buffer.h"
7 #include "bin/process.h" 7 #include "bin/process.h"
8 #include "bin/socket.h" 8 #include "bin/socket.h"
9 9
10 #include "include/dart_api.h" 10 #include "include/dart_api.h"
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 DartUtils::SetStringField( 152 DartUtils::SetStringField(
153 status_handle, "_errorMessage", os_error_message); 153 status_handle, "_errorMessage", os_error_message);
154 } 154 }
155 delete[] string_args; 155 delete[] string_args;
156 delete[] string_environment; 156 delete[] string_environment;
157 free(os_error_message); 157 free(os_error_message);
158 Dart_SetReturnValue(args, Dart_NewBoolean(error_code == 0)); 158 Dart_SetReturnValue(args, Dart_NewBoolean(error_code == 0));
159 } 159 }
160 160
161 161
162 void FUNCTION_NAME(Process_Wait)(Dart_NativeArguments args) {
163 Dart_Handle process = Dart_GetNativeArgument(args, 0);
164 Dart_Handle stdin_handle = Dart_GetNativeArgument(args, 1);
165 Dart_Handle stdout_handle = Dart_GetNativeArgument(args, 2);
166 Dart_Handle stderr_handle = Dart_GetNativeArgument(args, 3);
167 Dart_Handle exit_handle = Dart_GetNativeArgument(args, 4);
168 intptr_t process_stdin;
169 intptr_t process_stdout;
170 intptr_t process_stderr;
171 intptr_t exit_event;
172 Socket::GetSocketIdNativeField(stdin_handle, &process_stdin);
173 Socket::GetSocketIdNativeField(stdout_handle, &process_stdout);
174 Socket::GetSocketIdNativeField(stderr_handle, &process_stderr);
175 Socket::GetSocketIdNativeField(exit_handle, &exit_event);
176 ProcessResult result;
177 intptr_t pid;
178 Process::GetProcessIdNativeField(process, &pid);
179 if (Process::Wait(pid,
180 process_stdin,
181 process_stdout,
182 process_stderr,
183 exit_event,
184 &result)) {
185 Dart_Handle out = result.stdout_data();
186 if (Dart_IsError(out)) Dart_PropagateError(out);
187 Dart_Handle err = result.stderr_data();
188 if (Dart_IsError(err)) Dart_PropagateError(err);
189 Dart_Handle list = Dart_NewList(4);
190 Dart_ListSetAt(list, 0, Dart_NewInteger(pid));
191 Dart_ListSetAt(list, 1, Dart_NewInteger(result.exit_code()));
192 Dart_ListSetAt(list, 2, out);
193 Dart_ListSetAt(list, 3, err);
194 Dart_SetReturnValue(args, list);
195 } else {
196 Dart_Handle error = DartUtils::NewDartOSError();
197 Process::Kill(pid, 9);
198 if (Dart_IsError(error)) Dart_PropagateError(error);
199 Dart_ThrowException(error);
200 }
201 }
202
203
162 void FUNCTION_NAME(Process_Kill)(Dart_NativeArguments args) { 204 void FUNCTION_NAME(Process_Kill)(Dart_NativeArguments args) {
163 Dart_Handle process = Dart_GetNativeArgument(args, 1); 205 Dart_Handle process = Dart_GetNativeArgument(args, 1);
164 intptr_t pid = -1; 206 intptr_t pid = -1;
165 Process::GetProcessIdNativeField(process, &pid); 207 Process::GetProcessIdNativeField(process, &pid);
166 int signal = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); 208 int signal = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2));
167 bool success = Process::Kill(pid, signal); 209 bool success = Process::Kill(pid, signal);
168 Dart_SetReturnValue(args, Dart_NewBoolean(success)); 210 Dart_SetReturnValue(args, Dart_NewBoolean(success));
169 } 211 }
170 212
171 213
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 int external_length = strlen(system_string); 286 int external_length = strlen(system_string);
245 uint8_t* buffer = NULL; 287 uint8_t* buffer = NULL;
246 Dart_Handle external_array = IOBuffer::Allocate(external_length, &buffer); 288 Dart_Handle external_array = IOBuffer::Allocate(external_length, &buffer);
247 memmove(buffer, system_string, external_length); 289 memmove(buffer, system_string, external_length);
248 if (utf8 != system_string) free(const_cast<char*>(system_string)); 290 if (utf8 != system_string) free(const_cast<char*>(system_string));
249 Dart_SetReturnValue(args, external_array); 291 Dart_SetReturnValue(args, external_array);
250 } 292 }
251 293
252 } // namespace bin 294 } // namespace bin
253 } // namespace dart 295 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698