• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSTask not working for shell scripts?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: NSTask not working for shell scripts?
      • From: Yann Bizeul <email@hidden>
References: 
 >Re: NSTask not working for shell scripts? (From: Chris Ridd <email@hidden>)

  • Prev by Date: Re: NSTask not working for shell scripts?
  • Next by Date: Re: Debugging Cocoa Apps
  • Previous by thread: Re: NSTask not working for shell scripts?
  • Next by thread: Re: NSTask not working for shell scripts?
  • Index(es):
    • Date
    • Thread