Re: NSTask not working for shell scripts?
Re: NSTask not working for shell scripts?
- Subject: Re: NSTask not working for shell scripts?
- From: Robert Staflin <email@hidden>
- Date: Tue, 3 Dec 2002 16:06:10 +0100
OK, I'm using the TaskWrapper class from Apple (in the Moriarity
example). So, in my own class RoutRController I have:
...
getRouteTask=[[TaskWrapper alloc] initWithController:self
arguments:[NSArray arrayWithObjects:@"/usr/bin/getRoute", nil]];
// kick off the process asynchronously
[getRouteTask startProcess];
...
My shell script is called getRoute (and happens to be in /usr/bin/ at
the moment. It can be invoked with /usr/bin/getRoute of course.
startProcess is implemented in TaskWrapper with
...
task = [[NSTask alloc] init];
[task setStandardOutput: [NSPipe pipe]];
[task setStandardError: [task standardOutput]];
[task setLaunchPath: [arguments objectAtIndex:0]];
[task setArguments: [arguments subarrayWithRange: NSMakeRange (1,
([arguments count] - 1))]];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(getData:)
name: NSFileHandleReadCompletionNotification
object: [[task standardOutput] fileHandleForReading]];
[[[task standardOutput] fileHandleForReading]
readInBackgroundAndNotify];
[task launch];
...
I'm not specifying which shell to run in (i.e. bash/sh/tcsh) in the
script - there's only one line with "netstat -r" without the quotes.
/Robert
On tisdag, dec 3, 2002, at 14:50 Europe/Stockholm, Chris Ridd wrote:
>
On 3/12/02 1:05 pm, Robert Staflin <email@hidden> wrote:
>
>
> ? I don't think I understand the first line in your answer - the shell
>
> script should be run by the NSTask, and not the other way around...
>
> Thanks for the advice about the console - beginner mistake. It gave me
>
> info on the crash log which says:
>
[...]
>
> This tells me that Thread 0 crashed when trying the NSConcreteTask
>
> call, right? That's about the same I knew before - when my
>
> TaskWrapper.m has done:
>
>
>
> // launch the task asynchronously
>
> [task launch];
>
>
>
> ...it crashes.
>
>
>
> Anybody?
>
>
>
> Thanks for any input!
>
> /Robert
>
>
Backing up a bit, how exactly (code!) are you constructing the task
>
object
>
and all the arguments?
>
>
Cheers,
>
>
Chris
>
_______________________________________________
>
cocoa-dev mailing list | email@hidden
>
Help/Unsubscribe/Archives:
>
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>
Do not post admin requests to the list. They will be ignored.
>
>
==============================================
KRS Consulting
Robert Staflin
Jenny Linds vdg 75 Tel: +46 (18)
369425
S-756 50 UPPSALA Mobile: +46 (708) 369578
SWEDEN
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.