31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
#import "OFOutOfRangeException.h"
#import "OFReadFailedException.h"
#import "OFWriteFailedException.h"
#include <windows.h>
@interface OFSubprocess ()
- (of_char16_t *)of_wideEnvironmentForDictionary: (OFDictionary *)dictionary;
- (char *)of_environmentForDictionary: (OFDictionary *)environment;
@end
@implementation OFSubprocess
+ (instancetype)subprocessWithProgram: (OFString *)program
{
return [[[self alloc] initWithProgram: program] autorelease];
|
|
|
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
#import "OFOutOfRangeException.h"
#import "OFReadFailedException.h"
#import "OFWriteFailedException.h"
#include <windows.h>
@interface OFSubprocess ()
- (OFChar16 *)of_wideEnvironmentForDictionary: (OFDictionary *)dictionary;
- (char *)of_environmentForDictionary: (OFDictionary *)environment;
@end
@implementation OFSubprocess
+ (instancetype)subprocessWithProgram: (OFString *)program
{
return [[[self alloc] initWithProgram: program] autorelease];
|
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
if (containsSpaces)
[argumentsString appendString: @"\""];
}
if ([OFSystemInfo isWindowsNT]) {
size_t length;
of_char16_t *argumentsCopy;
STARTUPINFOW si;
memset(&si, 0, sizeof(si));
si.cb = sizeof(si);
si.hStdInput = _writePipe[0];
si.hStdOutput = _readPipe[1];
si.hStdError = GetStdHandle(STD_ERROR_HANDLE);
si.dwFlags |= STARTF_USESTDHANDLES;
length = argumentsString.UTF16StringLength;
argumentsCopy = of_alloc(length + 1,
sizeof(of_char16_t));
memcpy(argumentsCopy, argumentsString.UTF16String,
(length + 1) * 2);
@try {
if (!CreateProcessW(program.UTF16String,
argumentsCopy, NULL, NULL, TRUE,
CREATE_UNICODE_ENVIRONMENT,
[self of_wideEnvironmentForDictionary:
|
|
|
|
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
if (containsSpaces)
[argumentsString appendString: @"\""];
}
if ([OFSystemInfo isWindowsNT]) {
size_t length;
OFChar16 *argumentsCopy;
STARTUPINFOW si;
memset(&si, 0, sizeof(si));
si.cb = sizeof(si);
si.hStdInput = _writePipe[0];
si.hStdOutput = _readPipe[1];
si.hStdError = GetStdHandle(STD_ERROR_HANDLE);
si.dwFlags |= STARTF_USESTDHANDLES;
length = argumentsString.UTF16StringLength;
argumentsCopy = of_alloc(length + 1,
sizeof(OFChar16));
memcpy(argumentsCopy, argumentsString.UTF16String,
(length + 1) * 2);
@try {
if (!CreateProcessW(program.UTF16String,
argumentsCopy, NULL, NULL, TRUE,
CREATE_UNICODE_ENVIRONMENT,
[self of_wideEnvironmentForDictionary:
|
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
|
{
if (_readPipe[0] != NULL)
[self close];
[super dealloc];
}
- (of_char16_t *)of_wideEnvironmentForDictionary: (OFDictionary *)environment
{
OFMutableData *env;
OFEnumerator *keyEnumerator, *objectEnumerator;
OFString *key, *object;
const of_char16_t equal = '=';
const of_char16_t zero[2] = { 0, 0 };
if (environment == nil)
return NULL;
env = [OFMutableData dataWithItemSize: sizeof(of_char16_t)];
keyEnumerator = [environment keyEnumerator];
objectEnumerator = [environment objectEnumerator];
while ((key = [keyEnumerator nextObject]) != nil &&
(object = [objectEnumerator nextObject]) != nil) {
[env addItems: key.UTF16String count: key.UTF16StringLength];
[env addItems: &equal count: 1];
|
|
|
|
|
|
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
|
{
if (_readPipe[0] != NULL)
[self close];
[super dealloc];
}
- (OFChar16 *)of_wideEnvironmentForDictionary: (OFDictionary *)environment
{
OFMutableData *env;
OFEnumerator *keyEnumerator, *objectEnumerator;
OFString *key, *object;
const OFChar16 equal = '=';
const OFChar16 zero[2] = { 0, 0 };
if (environment == nil)
return NULL;
env = [OFMutableData dataWithItemSize: sizeof(OFChar16)];
keyEnumerator = [environment keyEnumerator];
objectEnumerator = [environment objectEnumerator];
while ((key = [keyEnumerator nextObject]) != nil &&
(object = [objectEnumerator nextObject]) != nil) {
[env addItems: key.UTF16String count: key.UTF16StringLength];
[env addItems: &equal count: 1];
|