Re: Java Tool with NSTask?
Re: Java Tool with NSTask?
- Subject: Re: Java Tool with NSTask?
- From: Fabio Genoese <email@hidden>
- Date: Sun, 25 Jan 2004 12:09:23 +0100
Hey,
thank you for your answer. I had tried that before but got an error
("Exception in thread "main" java.lang.NoClassDefFoundError"). It seems
I should have investigated this a little bit more. :) I forgot to pass
the classpath as argument... Got it running now.
Here's a code snipplet for those who are interested:
NSTask *myTask = [[NSTask alloc] init];
NSData *inData = nil;
NSPipe *myPipe = [NSPipe pipe];
NSFileHandle *myHandle = [myPipe fileHandleForReading];
NSArray *args = [[NSArray alloc] initWithObjects:@"-cp",[[[NSBundle
mainBundle] bundlePath]
stringByAppendingString:@"/Contents/Resources/"],@"test", nil]; //the
class I want to run is named test.class
NSString *output;
[myTask setStandardOutput: myPipe];
[myTask setLaunchPath:@"/usr/bin/java"];
[myTask setArguments:args];
[myTask launch];
inData = [myHandle readDataToEndOfFile];
output = [[NSString alloc] initWith
Data:[inData
subdataWithRange:NSMakeRange(0, [inData length])]
encoding:NSASCIIStringEncoding];
Sorry for this dumb question. :)
ciao,
Fabio
Am 25.01.2004 um 10:15 schrieb Sherm Pendley:
>
On Jan 25, 2004, at 3:30 AM, Fabio Genoese wrote:
>
>
> I would like to access a Java command line tool from Cocoa
>
> (Objective-C app). As you can imagine, I need its output. I know
>
> there's NSTask for UNIX command line tools and of course there's
>
> NSPureApplication in the Java AppKit for java tools (ONLY for the
>
> Java AppKit) but what about using java tools from Objective-C? Any
>
> ideas?
>
>
Couldn't you simply use NSTask to run /usr/bin/java just like you
>
would any other UNIX tool? All you'd need to do is pass the path to
>
your Java app as an argument, as well as any other relevant arguments
>
you'd use to run the app from a shell.
>
>
sherm--
_______________________________________________
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.