Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use pipes instead of creating tmp files for passing around data to th…

…e ruby interpreter.
  • Loading branch information...
commit b3f2171710910db0794d55609edd377ba6219d6c 1 parent d70de8e
@kommen kommen authored andrewfromcali committed
Showing with 11 additions and 8 deletions.
  1. +11 −8 data_AppDelegate.m
View
19 data_AppDelegate.m
@@ -77,20 +77,23 @@ - (BOOL)tableView:(NSTableView *)aTableView shouldSelectRow:(int)rowIndex {
[tempString release];
}
else if ([pops isEqualToString:@"Ruby Objects"]) {
- NSString *tempFile = @"/tmp/mc_results";
- [[NSFileManager defaultManager] createFileAtPath: tempFile contents: [NSData data] attributes: nil];
- [[NSFileManager defaultManager] createFileAtPath:@"/tmp/mc_data" contents:value attributes: nil];
-
+ NSPipe *inPipe = [NSPipe pipe];
+ NSPipe *outPipe = [NSPipe pipe];
+
+ NSFileHandle *inFile = [inPipe fileHandleForWriting];
+ [inFile writeData:value];
+ [inFile closeFile];
+
NSTask *myTask = [[NSTask alloc] init];
[myTask setLaunchPath: @"/usr/bin/ruby"];
- [myTask setArguments: [NSArray arrayWithObjects:@"-e", @"f = File.open(\"/tmp/mc_data\"); puts Marshal.load(f.read).inspect; f.close", nil]];
- [myTask setStandardOutput: [NSFileHandle
- fileHandleForWritingAtPath: tempFile]];
+ [myTask setArguments: [NSArray arrayWithObjects:@"-e", @"puts Marshal.load(STDIN.read).inspect", nil]];
+ [myTask setStandardInput: inPipe];
+ [myTask setStandardOutput: outPipe];
[myTask launch];
[myTask waitUntilExit];
[myTask release];
- NSString *tempString = [[NSString alloc] initWithData:[[NSFileManager defaultManager] contentsAtPath:tempFile]
+ NSString *tempString = [[NSString alloc] initWithData:[[outPipe fileHandleForReading] readDataToEndOfFile]
encoding:NSASCIIStringEncoding];
[text setString:tempString];
[tempString release];
Please sign in to comment.
Something went wrong with that request. Please try again.