Re: Submit background task
Re: Submit background task
- Subject: Re: Submit background task
- From: Sherm Pendley <email@hidden>
- Date: Thu, 16 Jun 2005 20:25:45 -0400
On Jun 16, 2005, at 10:24 AM, John Nairn wrote:
What is the best way (NSTask or other) to submit a background
process that will continue running even if the submitting
application quits? I tried an NSTask adding arguments ">", "output
file name", and "&", to redirect to a file and run in background,
but NSTask just passed the new arguments to the main task.
NSTask simply passes arguments as given to the launched task - it
doesn't interpret them like a command shell would. If you want to do
that, you could use NSTask to run /bin/sh, and pass the shell command
you want to execute as an argument, using sh's -c option. Something
like this:
NSArray *args = [NSArray arrayWithObjects:
// -c & shell command first
@"-c", @"/path/to/script > /
output/file 1>&2 &",
// Additional arguments are
passed to the script
@"--foo", @"--bar",
// Terminate the list
nil];
[NSTask launchedTaskWithLaunchPath:@"/usr/bin/sh" arguments:args];
Especially handy if you want to use multiple pipes in series,
something that's easy to do with | in a shell, but would require
multiple instances of NSPipe to do in code.
Another option would be to use old-school Unix functions fork() and
exec().
sherm--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
_______________________________________________
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