Re: NSTask with complexe command
Re: NSTask with complexe command
- Subject: Re: NSTask with complexe command
- From: Vincent Pottier <email@hidden>
- Date: Mon, 22 Mar 2004 11:50:33 +0100
It work perfectly thanks a lot.
Vincent
Le 22 mars 04, ` 01:37, Sailesh Agrawal a icrit :
Most people use Pseudo TTY for this. Checkout my example.
good luck !
Sailesh
On Thu, 18 Mar 2004 14:05:15 +0100, "Vincent Pottier"
<email@hidden>
said:
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.
<task>
_______________________________________________
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.