Re: using 'cp' with NSTask
Re: using 'cp' with NSTask
- Subject: Re: using 'cp' with NSTask
- From: Shawn Erickson <email@hidden>
- Date: Fri, 28 Jan 2005 08:47:57 -0800
On Jan 28, 2005, at 8:15 AM, Peter Browne wrote:
However, when it tries to run 'cp' the program chokes. Here is the relevent code:
NSString *copyPath = [mapView filePath];
NSString *targetPath = [NSString stringWithFormat:@"%@/Desktop/blah.pdf", NSHomeDirectory()];
NSLog(@"Going to copy from %@ to %@.", copyPath, targetPath);
NSArray *args = [NSArray arrayWithObjects:copyPath, targetPath];
// the task to handle copying of the map image
NSTask *cp = [NSTask launchedTaskWithLaunchPath:@"/bin/cp" arguments:args];
[cp launch];
The problem in the above is that you are calling arrayWithObjects: but you are not terminating your object listing with nil. Review the docs for how to use arrayWithObjects:. I bet use of the debugger would have pointed this out to you quickly, as well as the crash back trace.
Also you aren't emptying the stdout pipe the your NSTask will be dumping data into... if it dumps enough data then the task could stall waiting on the pipe to be emptied after a pipe full condition. In this case it is highly unlike that would happen given how little output cp will generate when copying one file but it is something to consider if you use NSTask more in the future.
-Shawn
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden