NSTask problems.
NSTask problems.
- Subject: NSTask problems.
- From: Olivier <email@hidden>
- Date: Wed, 24 Jul 2002 17:06:42 -0400
Hi,
I've decided to make my own CURL Handler.
So begin with the information at cocoadevcentral on wrapping UNIX commands.
They tell me to use NSTask so that's what I do.
After exploring NSTask in the foundation doc,
I have this code for a test app.
- (IBAction)loadURL:(id)sender
{
NSTask *cURLSession = [[NSTask alloc] init];
NSPipe *shellOutput =[[NSPipe alloc] init];
NSFileHandle *fileHandle;
NSString *result;
[cURLSession setLaunchPath:@"/usr/bin/curl"];
[cURLSession setArguments:[NSArray
arrayWithObjects:@"
http://ambush.avara.net/index.php",nil]];
[cURLSession setStandardOutput:shellOutput];
[cURLSession setStandardError:shellOutput];
fileHandle = [shellOutput fileHandleForReading];
[cURLSession launch];
while([cURLSession isRunning]) // While the proc. is running.
{
// Do nothing and wait till it's finished...
}
NSLog(@"Termination Status: %d",[cURLSession terminationStatus]);
result=[[NSString alloc] initWith
Data:[fileHandle readDataToEndOfFile]
encoding:NSASCIIStringEncoding];
[resultField setString:result];
[result release];
[shellOutput release];
[cURLSession terminate];
[cURLSession release];
}
I compile and open the app.
I click the button that triggers the IBAction loadURL
It loads like in 1 seconds: I'm in heaven.
But problems will arrive soon:
I decide to see If I can load another url, just for fun
I replace
http://ambush.avara.net/index.php for
http://www.apple.com
[cURLSession setArguments:[NSArray
arrayWithObjects:@"
http://www.apple.com",nil]];
I compile and run the app. The spinning multi colored ball appears. I wait
for 2 mins. Nothing loads. So I think " wow apple dot com is down! that's
rare!" So I fire up OmniWeb, enter www.apple.com
And the page loads. So I think " OH DAMN CURL WONT WORK! "
I fire up terminal and type curl
http://www.apple.com and it loads like
lightning.
Why cant it load in my app?
I use the same CURL in my app and in Terminal what's the problem. I also
used the same args..................
Can someone explain me the problem?
Thanks
-jean-olivier
_______________________________________________
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.