• 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: [Solved partially] NSTask with complexe command
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Solved partially] NSTask with complexe command


  • Subject: Re: [Solved partially] NSTask with complexe command
  • From: p3consulting <email@hidden>
  • Date: Sat, 20 Mar 2004 13:27:18 +0100

You get data in in stdin side of the pipe when the stdout side is
flushed.
If you want smaller chunks of data, you should look in the doc how the
set the NSUnbufferedIO variable environment,
probably something like

NSMutableDictionary *defaultEnv = [[NSMutableDictionary alloc]
initWithDictionary:[[NSProcessInfo processInfo] environment]] ;

[defaultEnv setObject:@"YES" forKey:@"NSUnbufferedIO"] ;

BEFORE launching the NSTask.
However stdout buffering may directly depend on how the tool you are
invoking is handling its output

Pascal Pochet
email@hidden


Le 20 Mar 2004, ` 12:24, Vincent Pottier a icrit :

> Well in fact, it was working, but the probleme is that i get data only
> when 8026 caracteres (don't know why this number) is sent to the
> NSFileHandle, then i got two notifications (4013 caracteres each) and
> i get data without any probleme.
> But for my use i need getting data even for small caracteres quantity.
> Does anyone have an idea, why i can't get small number of data?
> Thanks in advance.
> Vincent
>
> Le 18 mars 04, ` 14:05, Vincent Pottier a icrit :
>
>> Hello,
>> I'm writing an application who notify me when a new network
>> connection
>> is set. I've find a good way to do so: using tcpdump (available since
>> last security uptdate) via command:
>> sudo tcpdump -nqt 'tcp[tcpflags] & (tcp-syn|tcp-fin) != 0' //in fact
>> notify when connection closed to
>> So to use this command in cocoa i've write a daemon launch with
>> previlege (executeWithPrivilege...) calling tcpdump via NSTask and
>> NSFileHandle. And here is my problem, tcpdump is launch with sucess,
>> but no way to get the output, i'm using readInBackgroundAndNotify
>> (Full
>> code at mail end) but gotData: function is never call. So i've try
>> with
>> "tcpdump ip", gotData: fonction is call regulary, but no data is
>> available (i've lot of active connection).
>> Does someone know how to get output? Thanks in advance and sorry for
>> my poor English.
>> Vincent
>>
>> - (void)myFunction
>> {
>> NSTask *tcpdump=[[NSTask alloc] init];
>> NSPipe *pipe=[[NSPipe alloc] init];
>> handle = [[pipe fileHandleForReading] retain];
>>
>> [tcpdump setLaunchPath:@"/usr/sbin/tcpdump"];
>> [tcpdump setArguments:[NSArray arrayWithObjects:@"-nqt",
>> @"tcp[tcpflags] & (tcp-syn|tcp-fin) != 0", nil]];
>> [tcpdump setStandardOutput:pipe];
>>
>> [[NSNotificationCenter defaultCenter] addObserver:self
>> selector:@selector(gotData:)
>> name:NSFileHandleDataAvailableNotification
>> object:handle]; // async read
>> [handle waitForDataInBackgroundAndNotify];
>>
>> [tcpdump launch];
>> [tcpdump waitUntilExit];
>> }
>>
>> - (void)gotData:(NSNotification *)myNotification
>> {
>> NSData *messageData = [[myNotification userInfo] objectForKey
>> NSFileHandleNotificationDataItem];
>> NSString *string=[[NSString alloc] initWithData:messageData
>> encoding:NSASCIIStringEncoding];
>> NSLog(@"String data: %@", string);
>> [handle waitForDataInBackgroundAndNotify];
>> }
>> _______________________________________________
>> 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.
> _______________________________________________
> 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.
_______________________________________________
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.


References: 
 >NSTask with complexe command (From: Vincent Pottier <email@hidden>)
 >Re: [Solved partially] NSTask with complexe command (From: Vincent Pottier <email@hidden>)

  • Prev by Date: Re: Using bindings with an NSArray of NSStrings ?
  • Next by Date: Key-Value coding for mutable one-many value (Java)
  • Previous by thread: Re: [Solved partially] NSTask with complexe command
  • Next by thread: Re: NSTask with complexe command
  • Index(es):
    • Date
    • Thread